KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following class: public class StaticMethodsDemo { public static class A { public static A make() { return new A(); }; } public static class B extends A { public static B make() { return new B(); }; } public static class BPrime<T> extends A { public static <T> BPrime<T> make() { return new BPrime<T>(); }; } public static void main(String[] args) { B.make(); // compiles under Sun JDK 1.6.0_20 but fails under Oracle JDK 1.7.0_01. Why? BPrime.<Object>make(); } } compiles under Sun JDK 1.6.0_20 (Windows 64-bit, but shouldn't make a difference) but fails under Oracle JDK 1.7.0_01 (same platform) and OpenJDK 1.6.0_20 (Ubuntu) [1] with: [ERROR] StaticMethodsDemo.java:[37,14] error: reference to make is ambiguous, both method make() in A and method <T>make() in BPrime match Why? How does the generic parameter (which should be erased, no?) cause this apparent mismatch. Note that removing generics as follows: ... public static class BPrime<T> extends A { T val; public static BPrime<?> make() { return new BPrime<Object>(); }; public void setT(T val) { this.val = val; } } public static void main(String[] args) { B.make(); BPrime<Long> bprime = (BPrime<Long>) BPrime.make(); bprime.setT(Long.valueOf(10)); } compiles and runs too (so the generics hack doesn't cause any weird runtime casting errors). Issue 461: jclouds-core compilation fails using stock ubuntu openjdk
Tags (comma-separated)
Save Edits
Cancel