Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon
Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1748373] Tue, 22 November 2016 14:54 Go to next message
Marmi Thomas is currently offline Marmi ThomasFriend
Messages: 3
Registered: November 2016
Junior Member
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 20:26 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
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 Smile

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 #1748570 is a reply to message #1748408] Thu, 24 November 2016 15:01 Go to previous messageGo to next message
Marmi Thomas is currently offline Marmi ThomasFriend
Messages: 3
Registered: November 2016
Junior Member
Hello Stephan,

Thanks for your answer.

I'm going to fixed the code.

Quote:
reject by early access builds of Java 9.

- is it possible to disable the early access builds of java 9 in Neon ?

Quote:
Both compilers have been fixed in this regard.

- in which version of Java 8 is it fixed ?

Have a good day,

Thomas
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1748572 is a reply to message #1748570] Thu, 24 November 2016 15:15 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
is it possible to disable the early access builds of java 9 in Neon ?


Not sure what you mean here, Neon does not support Java 9. What I tried was: download Java 9 EA JDK and use its javac to compile from the command line.

Quote:
in which version of Java 8 is it fixed ?


It was fixed in javac, but not in version 8, only 9.

Maybe you missed may point when I compared the Oracle compiler ("javac") with ours ("ecj")?
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1748573 is a reply to message #1748572] Thu, 24 November 2016 15:46 Go to previous messageGo to next message
Marmi Thomas is currently offline Marmi ThomasFriend
Messages: 3
Registered: November 2016
Junior Member
Indeed, I misunderstood this point.

But now it's ok Smile

Thanks,

Thomas
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1753862 is a reply to message #1748573] Fri, 10 February 2017 21:09 Go to previous messageGo to next message
Alessandro Aiezza is currently offline Alessandro AiezzaFriend
Messages: 38
Registered: February 2017
Location: Nashville, TN
Member
This was a helpful back-and-forth to read through so thank you for that.
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?"

I'm not sure what to do to submit a bug to Eclipse.

Thank you,
Alex
Re: Java Type mismatch error on upgrade Eclipse Mars to Eclipse Neon [message #1755012 is a reply to message #1753862] Sun, 26 February 2017 12:43 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
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
Previous Topic:Eclipse DEBUG Logs
Next Topic:Building eclipse.jdt.ui fails test stage
Goto Forum:
  


Current Time: Wed Apr 24 17:11:39 GMT 2024

Powered by FUDForum. Page generated in 0.03904 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top