Java generics compile in Eclipse, but not in javac

后端 未结 5 1357
面向向阳花
面向向阳花 2020-12-16 14:49

I had to discover I have Java code in my project, which compiles and runs fine in Eclipse, but throws a compilation error in javac.

A self-contained snippet:

5条回答
  •  無奈伤痛
    2020-12-16 15:12

    It seems that Sun's 1.6 JDK can't infer the correct type. The following seems to work on my machine:

    Set setOfObjects = Main.covariantSet(setOfInts);
    
    
    

    Note that you must invoke the static method prefixed with the class name

    提交回复
    热议问题