I am confused about subtypes in Scala. My major question is how to distinguish C[T1]
from C[T2]
. There are two scenarios:
C[T1]
"equals"C[T2]
because they are all subtypes ofC
.C[T1]
does not "equal"C[T2]
becauseC[T1]
andC[T2]
are different types eventually.
I have tried some ways like .getClass
, seems that this strategy won't work because we have primitive types.
println(List[Int](1).getClass == List[Double](1.0).getClass) // True
println(List[Int](1).getClass.getCanonicalName) // scala.collection.immutable.$colon$colon
println(Array[Int](1).getClass == Array[Double](1.0).getClass) // False
println(Array[Int](1).getClass.getCanonicalName) // int[]
I now wonder is there some way I can do this?
Aucun commentaire:
Enregistrer un commentaire