I discovered this a few days ago, it seems Java 5 may have a small change in how it resolves methods. About a year and a half ago I wrote some code for Java 1.4 that looked like this:
public abstract class SuperClass extends Thread {
private LinkedList list;
public void run() {
Object o = list.removeFirst();
process(o);
}
public abstract void process(Object o);
}
public class SubClass extends SuperClass {
public void process(Object o) {
throw new RuntimeException("Unsupported Input!");
}
public void process(String s) {
}
public void process(Reader r) {
}
}
Obviously the code was more complex than this, but it demonstrates the difference. I was helping a friend with some code similar to this, and Java was calling the method that took Object even if there was a method that took a more specific type. I'm not sure what the difference in the bytecode is here. I know that usually Java mangles the name in these cases, but what does it call the method when it needs to be determined at runtime?
It still seems like this is a strange difference. Of course, there isn't a lot of code that uses this, and if the difference is the compiler then code compiled with the old compiler should still work on the Java 5 runtime. I still do wonder if there are any showstoppers in running full Java 1.4 applications on Java 5, has anyone found one?
No comments:
Post a Comment