What do user-defined value classes look like from Java?

前端 未结 1 1877
日久生厌
日久生厌 2021-01-17 21:46

I think I understand the new \"value class\" feature of Scala 2.10, by comparison with Haskell\'s newtype:

trait BoundedValue[+This] extends Any         


        
相关标签:
1条回答
  • 2021-01-17 22:24

    Value classes compile as normal classes, and may well appear as references.

    The magic in them is that, when the value class doesn't escape the scope, all traces of it are erased from code, effectively inlining all the code. And, of course, giving additional type safety.

    See also SIP-15, which explains the mechanics.

    0 讨论(0)
提交回复
热议问题