projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.89k stars 2.39k forks source link

Generics and static factory methods with @XArgsConstructor #811

Open lombokissues opened 9 years ago

lombokissues commented 9 years ago

Migrated from Google Code (issue 776)

lombokissues commented 9 years ago

:bust_in_silhouette: google@korelstar.de   :clock8: Jan 29, 2015 at 11:10 UTC

What steps will reproduce the problem?

public class Bar<T extends java.util.Collection<E>, E> { }

@ lombok.RequiredArgsConstructor(staticName = "create") public class Foo<T extends java.util.Collection<E>, E> { public final Bar<T, E> bar; }

When compiling these two classes with AndroidStudio (IntelliJ IDEA) or with "java -jar lombok.jar delombok", the following error occurs:

error: type argument T﹟1 is not within bounds of type-variable T﹟2 where T﹟1,E﹟1,E﹟2,T﹟2,E﹟3 are type-variables: T﹟1 extends Collection<E﹟2> declared in method <T﹟1,E﹟1>create(Bar<T﹟1,E﹟1>) E﹟1 extends Object declared in method <T﹟1,E﹟1>create(Bar<T﹟1,E﹟1>) E﹟2 extends Object declared in class Foo T﹟2 extends Collection<E﹟3> declared in class Bar E﹟3 extends Object declared in class Bar

What is the expected output? What do you see instead?

Using eclipse with its own compiler, compiling works without errors. However, using "java -jar lombok.jar delombok" the error occurs too, but the class is nevertheless processed correctly. It generates the following code (which is desired):

public class Foo<T extends java.util.Collection<E>, E> { public final Bar<T, E> bar;

@ java.lang.SuppressWarnings(&quot;all&quot;)
private Foo(final Bar&lt;T, E&gt; bar) {
    this.bar = bar;
}

@ java.lang.SuppressWarnings(&quot;all&quot;)
public static &lt;T extends java.util.Collection&lt;E&gt;, E&gt; Foo&lt;T, E&gt; create(final Bar&lt;T, E&gt; bar) {
    return new Foo&lt;T, E&gt;(bar);
}

}

What version of the product are you using? On what operating system?

lombok 1.16.0 JDK 1.8.0.25 Android Studio 1.0.2 Lombok Plugin 0.8.8

Please provide any additional information below.

I do not know, from where the error comes from. But since the generated code is correct, the error should not occur. It prevents AndroidStudio from building the project, which is bad.

lombokissues commented 9 years ago

:bust_in_silhouette: tterrag1098   :clock8: May 05, 2015 at 14:39 UTC

I too have encountered this issue, with this class: https://github.com/SleepyTrousers/EnderCore/blob/ed514c78cc0e72bad68373316e47b0cfdfd39471/src/main/java/com/enderio/core/common/util/Bound.java

It compiles the correct code (javap output): http://puu.sh/hCiIo.txt

But gives these errors when calling the method: http://puu.sh/hBIHu.txt

Oddly it runs fine in eclipse luna, but I am using jdk6 for that.

JDK/javac 1.8.0.40 used to compile

lombokissues commented 9 years ago

End of migration