Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1748373] |
Tue, 22 November 2016 09:54  |
Eclipse User |
|
|
|
Hi,
Since I upgraded Eclipse Mars to Eclipse Neon I have a Java Type mismatch error.
consider the following test case :
//On mars
public static void main(String[] args) {
List<String> s = new ArrayList<>();
s.add("1");
s.add("2");
s.add("3");
int i = Integer.parseInt(Collections.max(s, new StringComparator()));
System.out.println(i);
}
}
class StringComparator implements Comparator {
@Override
public int compare(Object o1, Object o2) {
return ((String) o1).compareTo((String) o2);
}
}
//With Eclipse Neon the same code return me Type mismatch: cannot convert from Object to String
- Has the Eclipse compiler change something between these 2 versions ?
- or is it only a configuration with error/warning java compiler ?
My Eclipse version :
Mars :
Eclipse IDE for Java Developers
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600
Neon:
Eclipse IDE for Java Developers
Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
If you need more informations feel free to ask,
Thanks,
have a good day !
Thomas
|
|
|
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1748408 is a reply to message #1748373] |
Tue, 22 November 2016 15:26   |
Eclipse User |
|
|
|
Marmi Thomas wrote on Tue, 22 November 2016 15:54
- Has the Eclipse compiler change something between these 2 versions ?
Yes, in that time frame we fixed around 60 compiler bugs 
Specifically, the JDT compiler rejects the program starting with 4.6M6.
I just checked your example against javac. Result: accepted by version 1.8, reject by early access builds of Java 9.
Ergo, it looks like accepting the program was a bug shared by ecj and javac. Both compilers have been fixed in this regard.
Background: with the unchecked warnings in the picture, JLS requires that the compiler basically discards any results from successful type inference, and erase any type arguments from a resolved method, hence "Collections.max(..)" really returns Object in this situation.
Advice:
1. AVOID raw types (they have been legacy ever since their introduction 11 years ago)!
2. If you can't avoid raw types APPLY §1!
best,
Stephan
|
|
|
|
|
|
|
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1755012 is a reply to message #1753862] |
Sun, 26 February 2017 07:43  |
Eclipse User |
|
|
|
Quote:I just thought I would bring this stackoverflow question to your attention.
"Should JDK 9 not allow Lambda Expression instantiation where final fields are referenced in the overridden method?"
That thread covers several topics, so I'm not sure which part of it you would like us to investigate.
Quote: I'm not sure what to do to submit a bug to Eclipse.
Given you already have an account at Eclipse.org it should just be a matter of visiting bugs.eclipse.org, or even directly: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT&component=Core
Just note that webmasters are facing big spam attacks and therefore have to find ways to block spammers (without blocking 'good' users like you). PLease see the green note at the top of the bugzilla page for details.
thanks,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.05455 seconds