What is the purpose of AnyVal?

Posted by DaoWen on Stack Overflow See other posts from Stack Overflow or by DaoWen
Published on 2012-09-29T17:49:28Z Indexed on 2012/09/29 21:37 UTC
Read the original article Hit count: 127

Filed under:

I can't think of any situation where the type AnyVal would be useful, especially with the addition of the Numeric type for abstracting over Int, Long, etc. Are there any actual use cases for AnyVal, or is it just an artifact that makes the type hierarchy a bit prettier?


Just to clarify, I know what AnyVal is, I just can't think of any time that I would actually need it in Scala. When would I ever need a type that encompassed Int, Character and Double? It seems like it's just there to make the type hierarchy prettier (i.e. it looks nicer to have AnyVal and AnyRef as siblings rather than having Int, Character, etc. inherit directly from Any).

© Stack Overflow or respective owner

Related posts about scala