I have several questions about singleton types, but since they are both very closely related, I send them under the same thread.
Q1. Why does # 1 not compile, but # 2 does?
def id(x: Any): x.type = x //
Q2. The type is correctly inferred in the case of String , but not in the case of other reference types that I tried. Why is this so?
scala> id("hello") res3: String = hello scala> id(BigInt(9)) res4: AnyRef = 9 scala> class Foo defined class Foo scala> id(new Foo) res5: AnyRef = Foo@7c5c5601
source share