The answer to In scala, is there any way to check if an instance is a singleton object or not? explains how to check whether an instance is statically known to be an object
. In other words, it won't work for this scenario:
object Obj
val x: Any = Obj
isSingleton(x)
Or even here:
trait Trait // not sealed
case Obj extends Trait
class Class extends Trait
val xs: Seq[Trait] = ...
xs.filter(isSingleton)
Unfortunately, I would like to handle this. Is there a good way to do this? Or at least a better one than x.getClass.getName.endsWith("$")
?