How can I find out whether a type is a singleton or not?
case object Foo
case class Bar(i: Int)
def isSingleton[A](implicit t: reflect.ClassTag[A]): Boolean = ???
assert( isSingleton[Foo.type])
assert(!isSingleton[Bar ])
How can I find out whether a type is a singleton or not?
case object Foo
case class Bar(i: Int)
def isSingleton[A](implicit t: reflect.ClassTag[A]): Boolean = ???
assert( isSingleton[Foo.type])
assert(!isSingleton[Bar ])
I want to add another possibility which is useful when you are on the level of
Symbol
(e.g. going down the sub types of type):Do you need a
ClassTag
(<:<
is deprecated inClassTag
)? If not, then it works this way: