Bug in eclipse compiler or in javac (“type parameters of T cannot be determined”)

The following code

public class GenericsTest2 {

    public static void main(String[] args) throws Exception {
        Integer i = readObject(args[0]);

    public static <T> T readObject(String file) throws Exception {
        return readObject(new ObjectInputStream(new FileInputStream(file)));
        // closing the stream in finally removed to get a small example

    public static <T> T readObject(ObjectInputStream stream) throws Exception {
        return (T)stream.readObject();

compiles in eclipse, but not with javac (type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object).

When I change readObject(String file) to

    public static <T> T readObject(String file) throws Exception {
        return (T)readObject(new ObjectInputStream(new FileInputStream(file)));

it compiles in eclipse and with javac. Who is correct, the eclipse compiler or javac?


I'd say it's the bug in the Sun compiler reported here and here, because if you change your line to the one below it works with both, which seems to be exactly what is described in the bug reports.

return GenericsTest2.<T>readObject(new ObjectInputStream(new FileInputStream(file)));

Need Your Help

Google app engine persists silently fail after first persist

java google-app-engine web-applications jdo

I have a servlet that is saving code people upload. They can upload multiple code files whose keys are then saved in a code collection. Everything works for exactly one request. After the first req...

Python Regular Expressions to implement string unescaping

python regex backreference

I'm trying to implement string unescaping with Python regex and backreferences, and it doesn't seem to want to work very well. I'm sure it's something I'm doing wrong but I can't figure out what...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.