Consider the following standalone sample:
package bloopers; import java.lang.annotation.Annotation; public final class Blooper5 { interface Converter<T,F> { T convert( F from ); } interface Identifier<T> { } static class ConvertingIdentifier<F,T> implements Identifier<F> { ConvertingIdentifier( Converter<T,F> converter ) { } } static final class AnnotationIdentifier { Identifier<Annotation> I1 = new ConvertingIdentifier<>( a -> a.annotationType() ); Identifier<Annotation> I2 = new ConvertingIdentifier<>( Annotation::annotationType );
The above code compiles only under the following conditions:
javac from the command line.IntelliJ IDEA configured to use the javac compiler.
But it does not compile with the following:
EclipseIntelliJ IDEA configured to use the Eclipse compiler.
Eclipse cannot compile a string with <-- ERROR by specifying the following message:
The constructor Blooper5.ConvertingIdentifier<Annotation,Class<capture#5-of ? extends Annotation>>(Blooper5.Converter<Class<? extends Annotation>,Annotation>) is undefined
Admittedly, this code really pushes the general possibilities of outputting parameters like a compiler, but still I would like to know exactly what a mismatch is, no matter how small.
Some impact of my methods in case someone can see something wrong that I don’t see:
The command I used to compile with javac was "c:\Program Files\Java\jdk1.8.0_40\bin\javac" Blooper5.java .
I have IntelliJ IDEA version 14.1. In Project Structure/SDKs , I only have "1.8", which points to C:\Program Files\Java\jdk1.8.0_40 , and in Project Structure/Modules specific module is configured to use "Project SDK (1.8)", which is displayed like 1.8 (java version "1.8.0_40") .
As for Eclipse, I am using Eclipse for RCP and RAP Developers - Version: Luna Release (4.4.0) - Build id: 20140612-0600 . In Preferences/Java/Installed JREs , I only have jdk1.8.0_40, and it is by default. In the Execution Environments section, it is also verified as "Java J-1.8" Compatible JRE. And in my Project/Properties/Java Build Path/Libraries "JRE System Library" [jdk1.8.0_40] .
More noteworthy facts:
It is not only me; it also fails to install the (very similar) eclipse collective.
IntelliJ IDEA says that the expression lambda a -> a.annotationType() can be replaced with a method reference, but if asked to do it, it will not convert it to Annotation::annotationType ; instead, it converts it to (Converter<Class<? extends Annotation>, Annotation>) Annotation:: annotationType .
So the question is:
What causes these discrepancies between Eclipse and others, and what can be done to resolve these discrepancies?
(Obviously, the goal is to eliminate, unfortunately, a scenario that is too common when one developer compiles code that does not compile to another developer IDE.)
EDIT: When I originally posted this question, I thought that IDEA using the Eclipse compiler also compiled fine, but I was wrong. It turns out that it is possible that IDEA will not be able to compile the above code by choosing the Eclipse compiler. However, the question is why there is a discrepancy between eclipse and javac.