groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Undeclared type variable: T when calling a method from a class with a trait from java
Date Mon, 01 Aug 2016 07:57:51 GMT
that sounds like a bug in the code generated by the groovy compiler for 
the one of the fields you use. Though I remember a bug like this being 
fixed... Can you ell us what groovy version you use? Also... that error 
message from Java is strangely descriptive. Normally you end up with a 
some very cryptic stuff from inside the jdk... could you tell me what 
Java version you use as well?

bye Jochen

On 01.08.2016 00:08, abosch wrote:
> 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