Tried to:Jak przetestować wartość na byciu AnyVal?
scala> 2.isInstanceOf[AnyVal]
<console>:8: error: type AnyVal cannot be used in a type pattern or isInstanceOf test
2.isInstanceOf[AnyVal]
^
a to:
scala> 12312 match {
| case _: AnyVal => true
| case _ => false
| }
<console>:9: error: type AnyVal cannot be used in a type pattern or isInstanceOf test
case _: AnyVal => true
^
Przesłanie jest bardzo pouczające. Rozumiem, że nie mogę tego użyć, ale co mam zrobić?
Lub jeśli nie chcesz używać sztuczki 'null': def testAnyVal [T] (x: T) (implicit m: Manifest [T]) = m <:
@TravisBrown - lub jeśli nie chcesz pisać jawnego parametru jawnego, 'def testAnyVal [T: Manifest] (t: T) = manifest [T] <:
@Rex: Right, ładniej - po prostu trzymałem się ściśle sformułowania Thipora. –