Why does classOf[A.type] not compile?

195 Views Asked by At

The signature of Predef.classOf is

def classOf[T]: Class[T]

so emulating the above signature with

object Foo
def f[T]: Class[T] = null

why the following compiles

f[Foo.type]         // ok

but the following errors in Scala

classOf[Foo.type]   // error: class type required but Foo.type found

EDIT: In Scala 2.13.4 and onwards the above does works (as pointed out in the comments), however similar compile-time error still happens in the following scenario

val foo: Foo.type = Foo

f[foo.type]         // ok              
classOf[foo.type]   // error: class type required but foo.type found    
0

There are 0 best solutions below