eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
156 stars 123 forks source link

Code compiling in javac does not compile in eclipse #136

Open cdietrich opened 2 years ago

cdietrich commented 2 years ago

the following code (borrowed from https://github.com/google/guice/blob/e960b66d3d5931b9cb1aebd49e452e2c489a921e/core/src/com/google/inject/spi/BindingSourceRestriction.java#L348) seems to compile in javac (tested with temurin 11) but does not compile in eclipse

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.stream.Stream;

public class BugTest {
    private static Stream<Class<? extends Annotation>> getPermits(Class<?> clazz) {
        Stream<Annotation> annotations = Arrays.stream(clazz.getAnnotations());
        return annotations.map(Annotation::annotationType).filter(a -> a.isAnnotationPresent(MyAnno.class));
    }

    public static @interface MyAnno {

    }
}

cannot convert from Stream<Class<capture#2-of ? extends Annotation>> to Stream<Class<? extends Annotation>> BugTest.java

trancexpress commented 2 years ago

The type of this is not evaluated correctly: annotations.map(Annotation::annotationType)

Giving it the proper type (by creating a local variable with the correct type) "works". Probably something with method references not working as expected.

cdietrich commented 2 years ago

same for explicitely passing type

    private static Stream<Class<? extends Annotation>> getPermits(Class<?> clazz) {
        Stream<Annotation> annotations = Arrays.stream(clazz.getAnnotations());
        return annotations.<Class<? extends Annotation>>map(Annotation::annotationType).filter(a -> a.isAnnotationPresent(MyAnno.class));
    }