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.