开发者

What are AnyVal.types useful for?

开发者 https://www.devze.com 2023-04-05 09:31 出处:网络
I\'ve accidentally written this line of code: scala> val f = Int f: Int.type = object scala.Int Seems开发者_StackOverflow社区 to work for every subtype of AnyVal except for AnyVal itself.

I've accidentally written this line of code:

scala> val f = Int
f: Int.type = object scala.Int

Seems开发者_StackOverflow社区 to work for every subtype of AnyVal except for AnyVal itself.

Is there anything I can use f for or is it just an implementation detail of Scala leaking out?


The Int companion object is documented here. It doesn't provide a lot, but here are a couple things:

scala> val f = Int
f: Int.type = object scala.Int

scala> f.MaxValue
res1: Int = 2147483647

scala> f.box(2)
res2: java.lang.Integer = 2
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号