|
|
|
|
|
by teraflop
3376 days ago
|
|
Fun fact: in Java versions 5 and 6, it was actually possible to write valid Java source code with overloaded return types! The trick is that generic types in Java are subject to type erasure at runtime. Due to an oversight, it was possible to declare a class with methods like: String foo(List<X> l);
double foo(List<Y> l);
which would be erased to: String foo(List l);
double foo(List l);
At runtime, even though the type information for your List was no longer available, the compiler would be able to locate the correct method using the method signature stored in the caller's bytecode, giving the appearance of return-type dispatch. Technically this violates the Java language spec, and javac 7 was updated to be stricter and prevent this sort of code: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6182950I guess it's ultimately not that mysterious, but I first encountered it "in the wild", and ended up scratching my head for a while before I figured out why our code suddenly stopped compiling when we upgraded the JDK. |
|
It don't know that it was an appearance, my understanding is it is return-type dispatch which is supported by the JVM (but not java).