From: Tatu T. <tat...@ma...> - 2004-10-22 22:14:33
|
I posted earlier about reflection problems under Java 5. The invoker prefers superclass methods over subclass methods, which is fine with interfaces, but causes problems in the StringBuffer scenario. I don't know if my solution is the right one in all situations but it solved my specific problems. I made the following change to jsint/Invoke.java: Change: /** Only add an instance method if no superclass provides one. **/ private static void maybeAdd(Vector result, Method m1) { for(int i = 0; i < result.size(); i++) { Method m2 = ((Method) result.elementAt(i)); if(parameterTypesMatch(getParameterTypes(m1), getParameterTypes(m2))) return; } result.addElement(m1); } To the following: /** Only add an instance method if no superclass provides one. **/ private static void maybeAdd(Vector result, Method m1) { for(int i = 0; i < result.size(); i++) { Method m2 = ((Method) result.elementAt(i)); if(parameterTypesMatch(getParameterTypes(m1), getParameterTypes(m2))) { /* TTA: prefer methods provided by the subclass over superclass methods, * but not over interface methods. */ if(!m2.getDeclaringClass().isInterface()) result.set(i, m1); return; } } result.addElement(m1); } -- Tatu Tarvainen |