Archive for the ‘quiz’ Category
Little Java Generic Quiz
Let say I have following code:
interface TestGeneric { public Integer test(List<Integer> a); public Boolean test(List<Boolean> a); }
Can you guess what are the answers for following questions?
- TestGeneric will be reported as error by Java 6 (true/false)
- TestGeneric will be reported as error by Java 7 (true/false)
- TestGeneric will be reported as error by Eclipse 3.5 using Java 6 (true/false)
- TestGeneric will be reported as error by Eclipse 3.5 using Java 7 (true/false)
- TestGeneric will be reported as error by (upcoming) Eclipse 3.6 using Java 6 (true/false)
- TestGeneric will be reported as error by (upcoming) Eclipse 3.6 using Java 7 (true/false)
What’s your guess?
The correct answer is (highlight to see the answer): false, true, false, (can Eclipse 3.5 run Java 7?)?, true, true.
The fact that statement 1 is false is related to this bug entry: http://bugs.sun.com/view_bug.do?bug_id=6182950
Eclipse (as 3.6M2) offered a more consistent behavior by considering all cases as compile error as discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=289247
And this op4j used exactly this feature and will not be compiled under Java 7 or using Eclipse 3.6.
Related posts:
- Java Tips: Using generic correctly
- Be extremely careful when you initialize a non-final field in the declaration!
- Java Tips: Memory Optimization for String
Little Java Generic Quiz originally appeared on satukubik on April 16, 2010.