From: <bc...@wo...> - 2001-04-04 18:55:20
|
[Kent Johnson} >At 3:42 AM -0700 4/4/01, Finn Bock wrote: >>Keep in mind that python class can't overload a method name. Instead it >>can define different numbers of arguments to the same method. > >So, if a jython class overrides a method from a Java superclass, >- The jython class can only have one implementation of the method (no >overloaded methods in Python) >- Any call to that method name, regardless of actual arguments, will >be sent to the jython method > >Is that right? Yes. >Would it be possible for the runtime to look at the >number of arguments, at least, I suppose jython could for the very common case of methods. Looking at argument count (or better looking at argument types as well as count) just strikes me as unpythonic. Keep in mind that the method could be any kind of callable and checking the argument count/types of all callables is not possible. >and look up the inheritance hierarchy to find a method match? This is what the overriden "showData" methods look like. It attempts to find a python method called "showData" and then call it if found. public void showData(test.Data arg0) { PyObject inst = Py.jfindattr(this, "showData"); if (inst != null) inst._jcall(new Object[] {arg0}); else super.showData(arg0); } public void showData(java.lang.String arg0, int arg1) { PyObject inst = Py.jfindattr(this, "showData"); if (inst != null) inst._jcall(new Object[] {arg0, Py.newInteger(arg1)}); else super.showData(arg0, arg1); } Fitting in an arg count/type match into this simple dictionary lookup is difficult. regards, finn |