groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abosch <>
Subject Undeclared type variable: T when calling a method from a class with a trait from java
Date Sun, 31 Jul 2016 22:08:33 GMT

I have the following problem, maybe someone can help me here, thx :):

I have a trait, which adds recursive behaviour to a class like a

trait RecursiveEntity<T extends RecursiveEntity<T>> extends Entity {
   T successor;
   final List<T> subEntities = new ArrayList<T>();

   void setParent(final T newParent) {
      if (successor) {
         successor.removeSubEntity(this as T);
      successor = newParent;
      if (newParent) {
         newParent.addSubEntity(this as T);

   void addSubEntity(final T newEntity) {
      def parent = newEntity.successor;
      if (parent) {
      newEntity.successor = this as T;

   void removeSubEntity(final T toRemove) {
      if (toRemove.successor == this) {
         toRemove.successor = null;

class DirectoryEntity implements RecursiveDirectoryEntity {

   Container<FileEntity> container = new Container<>()

If I construct a DirectoryEntity from within Java code and use any method, I
get following Error message: Error:(13, 24) java: cannot access$Trait$FieldHelper   bad
class file:
undeclared type variable: T     Please remove or make sure it appears in the
correct subdirectory of the classpath. 

Is there a solution to my problem? I already had to remove multiple trait
usage and introduce Delegates because java can't handle it.

 To just use groovy code is not an option as my coworker's project is plain
 Big thx you and greets! Artur 

View this message in context:
Sent from the Groovy Users mailing list archive at

View raw message