views:

122

answers:

1

I am trying to create a static entry to a bunch of non-static util methods and getting this error with the sun compiler that I am not getting in eclipse:
"type parameters of X cannot be determined; no unique maximal instance exists for type variable X with upper bounds X,java.lang.Object"

public class Resource {  
  protected <X> X fromJson(String text, Class<?> type) {    
       ...  
    }

  public static <X> X convertFromJson(String json, Class<?> type) {  
      Resource r = new Resource();  
      return r.fromJson(json , type);  /// barfs here
      }  

My head hurts after returning from the Generics universe, so I'll rest and hope someone can provide some assistance before I get back to it tomorrow.... :) thanks

A: 

The type inference done by Eclipse is wrong, see JLS3 $15.12.2.8. (It must be inferred as Object)

You can explicitly

return r.<X>fromJson(json , type);

or

X x = r.fromJson(json , type); // type inference due to assignment
return x;

There has been too many questions about eclipse compiler being incompatible with standard. Most times it tries to be more loose and relaxed. This is disgusting. Is IBM trying to screw the language? (9/22/2010: http://basementcoders.com/?p=721 Gosling on IBM: "They'd do anything they can to screw Sun over. I mean, they didn’t name Eclipse casually. " )


http://stackoverflow.com/questions/2040843/java-generics-who-is-right-javac-or-eclipse-compile

http://stackoverflow.com/questions/757623/bug-in-eclipse-compiler-or-javac

http://stackoverflow.com/questions/3452859/java-generics-code-compiles-with-javac-fails-with-eclipse-helios

http://stackoverflow.com/questions/3000177/compilers-behave-differently-with-a-null-parameter-of-a-generic-method

http://stackoverflow.com/questions/314572/bug-in-eclipse-compiler-or-in-javac


Some words for people who throw "it's a bug in javac" without giving quotes from spec, but just because "I feel it should compile": 1. you don't know what a bug is. 2. programming is not like chick movies.

EDIT --- 9/23/2010

Pascal Thivent gave more examples of javac bugs. I thank him for that.

These bugs are from 2005, a year after Sun's release of Java 5.0, a monumental release. Of course javac has a lot of bugs too, and Eclipse got it right sometimes where javac got it wrong. I can't reproduce these bugs with javac 6. Reading recent/open Eclipse JDT bugs that behaves different from javac, I find more cases that Eclipse admits to be at fault than cases they think javac is wrong. However, this is the bug database about Eclipse bugs, so the stats may not be fair.

I maintain my dislike of IBM's general business strategies about Java.

I may have insulted people in IBM who do real field works and spend a lot of efforts sincerely improving IBM's Java products. I apologize to these people.

For this particular bug, it is reported to Eclipse as early as 2005-11-28

https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273

Philippe Mulet closed it thinking it's a javac bug. In 2008 he reopened it admitting it's Eclipse bug. The bug is supposed to be fixed in 2009. However in 2010, on Stackoverflow, I'm still seeing many reports of the same bug. Not sure what's going on.

irreputable
I wouldn't be so categoric. There are many examples where the eclipse compiler (ecj) is correct while the Sun compiler isn't, as reported on the Sun [forums](http://forums.sun.com/thread.jspa?threadID=5395128) or in previous questions here on SO. And actually, the consensus seems to be that ecj is more spec compliant that Sun's javac in general. Just raise a bug in Eclipse bug tracker, they'll fix it.
Pascal Thivent
you give ONE reference, which cannot even be reproduced, because neither the 1st nor the 3rd post give enough source code to check their claim. these guys are talking up crap with no substance. I'm not surprised you like it though, with your "actually, the consensus" which is totally made up.
irreputable
Quoting Kevin Bourrillion in a comment to [this answer](http://stackoverflow.com/questions/2040843/java-generics-who-is-right-javac-or-eclipse-compile/2041170#2041170) (that you can't see because it has been deleted): *"In my experience, eclipse is more likely to implement the spec correctly than javac. – Kevin Bourrillion"*. And believe it or not, I find feedback from the Guava Lead much more valuable than your nonsensical rant based on ONE example. Not surprising from you anyway. And because I don't like your tone nor your attitude, I'm done now.
Pascal Thivent
I find the view of the Java Language Designers more valuable than someone who wrote some utility classes. Thank you for leaving me alone. I always want to build my arguments rigorously, back 'em up with solid evidence and logic; not a fan of whimsical conclusions out of thin air.
irreputable
@irreputable - Your *"Is IBM trying to screw the language?"* is not a rational response. Where is your *evidence* that IBM is trying to subvert the Java language? A bug in the IBM compiler is not evidence of malicious intent ... IMO.
Stephen C
Setting the controversy aside for a moment.... @irreputable response works for me... much appreciated.... ok, as your were.
Rondo
*I always want to build my arguments rigorously, back 'em up with solid evidence and logic;* Ahem, what did you smoke? It must be strong. Reread your answer, your **free** claim, your comments and tell me that you're not contradicting yourself. Ridiculous...
Pascal Thivent
-1 for unrelated and unsupported tirade. Also, in my personal experience, when I've found a difference between javac and ecj, Eclipse has been more compliant. Becoming emotional about it either way is a ridiculous response, and not fitting for SO.
Mark Peters
@mark-peters I've listed my proofs, where's yours? Come on, name one. I'm not afraid of discussing specific cases, are you? I have heard so many people claiming Eclipse compiler more compliant to JSL, without ANY sustainable example. **You guys** are the one who based your opinion on your feelings, instead of facts and logic. In my book such intellectual laziness and dishonesty is far more damning than my one sentence of IBM bashing. Once again, to quote Gosling on IBM: "They'd do anything they can to screw Sun over. I mean, they didn’t name Eclipse casually. "
irreputable
@irreputable: I've discussed this in other places, but I won't discuss it with you. You have the wrong attitude for somebody who claims to be engaged in intellectual debate...case in point, your use of **"you guys"**. You're not in it for the debate, you're emotional, you're in it for the fight, and I'm not going to feed you, troll.
Mark Peters
@mark-peters yes, continue your talk about emotions, sensitive ladies. why don't you girls just give me ONE example to shut me up?
irreputable
@Mark: Saying "I'm right and I won't explain why" is also trolling.
R. Bemrose
@R. Bemrose: Yep, and I never said that. I said he made an unrelated and unsupported tirade. That tirade was about IBM apparently trying to "screw" Sun. It's unrelated because it has nothing to do with the question, and it's unsupported because a couple of weeks later and the only evidence he had for it was hearsay from a 26-year Sun employee. I didn't mark it down for his views on javac being more compliant than ecj.
Mark Peters
Whatever guys, I'm most interested in specific cases, I'll be glad to hear concrete examples. What really irritated me is Pascal Thivent's made up "consensus". That is very offensive to me intellectually. Made up "consensus" is usually uttered by politicians to completely ignore opponents' point as if they are garbage.
irreputable
Pascal Thivent
@Pascal Thivent thanks for the examples.
irreputable
Guys, can we please keep it civil? Debate is good but not when we're calling one another names. If you have some anger built up inside of you, please take it out elsewhere, not here.
musicfreak
@irreputable No problem. And I thank you too for the update of your answer.
Pascal Thivent