I’m trying to use Scala to find the base class (other than java.lang.Object) of a sequence of Java classes. I have defined a recursive function:
def baseClass(cls: Class[_]): Class[_] = {
val nextClass = cls.getSuperclass
nextClass match {
case java.lang.Object => cls
case _ => baseClass(nextClass)
}
}
The compiler gives the following error:
error: object Object is not a value
How to I properly terminate the recursion and return the class just below java.lang.Object?
Except that that doesnt help you since Object is a superclass of what you are matching on.
This function does what you want.