I have an abstract Java class called ImmutableEntity and several subclasses that contain class level annotation called @DBTable . I am trying to search for class hierarchy for annotation using the Scala tail recursive method:
def getDbTableForClass[A <: ImmutableEntity](cls: Class[A]): String = { @tailrec def getDbTableAnnotation[B >: A](cls: Class[B]): DBTable = { if (cls == null) { null } else { val dbTable = cls.getAnnotation(classOf[DBTable]) if (dbTable != null) { dbTable } else { getDbTableAnnotation(cls.getSuperclass) } } } val dbTable = getDbTableAnnotation(cls) if (dbTable == null) { throw new IllegalArgumentException("No DBTable annotation on class " + cls.getName) } else { val value = dbTable.value if (value != null) { value } else { throw new IllegalArgumentException("No DBTable.value annotation on class " + cls.getName) } } }
When I compile this code, I get the error: "the @tailrec annotated method could not be optimized: it is called recursively with different type arguments." What is wrong with my internal method?
Thanks.
Ralph source share