Java generics code compiles with javac, fails with Eclipse Helios

后端 未结 8 1657
挽巷
挽巷 2020-12-16 02:53

I have the following test class that uses generics to overload a method. It works when compiled with javac and fails to compile in Eclipse Helios. My java version is 1.6.0_2

8条回答
  •  余生分开走
    2020-12-16 03:47

    After some research, I have the answer:

    The code, as it is specified above should NOT compile. ArrayList and ArrayList, at runtime is still ArrayList. But your code is not working because the returning type. If you set the same returning types for both methods, javac won't compile that...

    I read that there is a bug in Java 1.6 (that is already fixed in Java 1.7) about this error. Is all about returning types... so, you will need to change the signature of your methods.

    There is the bug 6182950 in Oracle's Bug Database.

提交回复
热议问题