Scala: problems with erasing when overriding an equal function for parameterized classes

I am having trouble understanding how to use manifests.

What is my problem: I created a new parameterized class C and tried to override such values:

override def equals(that:Any)=that match{
 case that:C[T] => true /*do smth else not relevant*/
 case _ => false
}

Of course, I get a "warning: the invariant type argument T in a template of type C [T] is not checked, because it is eliminated by erasing." I tried using manifests, as I used in many other functions:

override def equals(that:Any)(implicit manifest:Manifest[T])=that match{
 case that:C[T] => true
 case _ => false
}

But I realized that the error message: the method does not overlap anything either.

I do not know how to fix this. Can anyone help me out?

+5
source share
3 answers

. java. equals def equals(x: Any): Boolean - .

, == desugaring -, - def defEquals [T] (x: T) ( equiv: Equiv [T]) " , , , , .

+5

@extempore; , . Scalaz Identity ( )

new Fruit โ‰  new Orange //does not compile
new Apple โ‰Ÿ new Apple  //compiles!

, (.. C[T] == C[U] iff T =:= U


, :

def foo(bar : Bar) : Baz

:

def foo(bar : Bar) ( implicit bat : Bat) : Baz

, . , . , scala override: , , , , !

+4
  override def equals(that:Any)= {
    that match{            
      case that:C[x] => true
      case _ => false                                     
    }
  }

, , , . , ( ), , ( ) . (: , , . , , ).

-1

All Articles