groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abosch <arturbo...@gmx.de>
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
Heyho,

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
DirectoryEntity.

@CompileStatic
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) {
      Validate.notNull(newEntity)
      def parent = newEntity.successor;
      if (parent) {
         parent.removeSubEntity(newEntity);
      }
      newEntity.successor = this as T;
      subEntities.add(newEntity);
   }

   void removeSubEntity(final T toRemove) {
      Validate.notNull(toRemove)
      if (toRemove.successor == this) {
         subEntities.remove(toRemove);
         toRemove.successor = null;
      }
   }
...
}

@CompileStatic
class DirectoryEntity implements RecursiveDirectoryEntity {

   @Delegate
   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
de.unibremen.st.entitygraph.traits.RecursiveEntity$Trait$FieldHelper   bad
class file:
/home/artur/Arbeit/tools/entitygraph/build/classes/main/de/unibremen/st/entitygraph/traits/RecursiveEntity$Trait$FieldHelper.class
   
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
java...
 Big thx you and greets! Artur 



--
View this message in context: http://groovy.329449.n5.nabble.com/Undeclared-type-variable-T-when-calling-a-method-from-a-class-with-a-trait-from-java-tp5734382.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Mime
View raw message