Java's visibility rules are tricky at times. Do you know what this will print? package p; import static p.A.x; class A { static String x = "A.x"; } class B { String x = "B.x"; } class C { String x = "C.x"; class D extends B { void m() { System.out.println(x); } } } … Continue reading A Curious Java Language Feature and How it Produced a Subtle Bug
Tag: subtype polymorphism
The Dangers of Correlating Subtype Polymorphism with Generic Polymorphism
Java 5 has introduced generic polymorphism to the Java ecosystem. This has been a great addition to the Java language, even if we're all aware of the numerous caveats due to generic type erasure and the consequences thereof. Generic polymorphism (also known as parametric polymorphism) is usually maintained orthogonally to possibly pre-existing subtype polymorphism. A … Continue reading The Dangers of Correlating Subtype Polymorphism with Generic Polymorphism