provato questo:Come testare un valore su AnyVal?
scala> 2.isInstanceOf[AnyVal]
<console>:8: error: type AnyVal cannot be used in a type pattern or isInstanceOf test
2.isInstanceOf[AnyVal]
^
e questo:
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
^
Il messaggio è molto istruttiva. Capisco che non posso usarlo, ma cosa dovrei fare?
Oppure se non si desidera utilizzare il trucco 'null':' def testAnyVal [T] (x: T) (implicito m: Manifest [T]) = m <:
@TravisBrown - O se non si desidera scrivere un parametro manifest esplicito, 'def testAnyVal [T: Manifest] (t: T) = manifest [T] <:
@Rex: Right, è più bello - stavo semplicemente attaccando più strettamente alla formulazione di Thipor. –