From: Updike, C. <Cla...@jh...> - 2004-08-24 14:21:20
|
This behavior (and the workaround) is pretty clearly documented. From: <http://www.jython.org/docs/usejava.html> (see Overloaded Java Method Signatures) If you need to call a Java method with a particular signature and this is not happening in the easy way, you can use the following workaround: Assume that foo has two methods, "void foo(int x); void foo(byte x);". To call the second method you could write the following: from java.lang import Byte foo(Byte(10)) And note the comment on that page that there may not be a better solution to the issue. -Clark -----Original Message----- From: On Behalf Of Jorgo Bakker Sent: Tuesday, August 24, 2004 9:59 AM To: Jython Users Subject: [Jython-users] Boolean hooks mistakenly preferred over Integer hooks? Dear all, Attached code is showing a kind of behavior that seems to be a bug. Could anybody confirm that this is indeed a bug, or else point me in the right direction? A work-around may be to implement a single __call__(Object o) method and doing the reflection myself. I am a bit stuck to interfaces within a larger context; such change is deemed to be a last resort. regards - Jorgo Bakker |
From: Updike, C. <Cla...@jh...> - 2004-08-24 14:43:17
|
It is somewhat unobvious, but the place to implement the workaround is where you actually assign the result to your 'o' variable. If you know it is a specific type (such as Integer), always assign it like this: o = java.lang.Integer( <some expression> ) You should get the desired behavior, viz: Jython 2.1 on java1.3.1_01 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import java.lang.Boolean as B >>> b = B.TRUE >>> b 1 >>> b = B(B.TRUE) >>> b true What's interesting about that example is the Boolean.TRUE is already a Boolean type, yet you still need to wrap it to get the desired behavior. -Clark -----Original Message----- From: jyt...@li... [mailto:jyt...@li...] On Behalf Of Jorgo Bakker Sent: Tuesday, August 24, 2004 9:59 AM To: Jython Users Subject: [Jython-users] Boolean hooks mistakenly preferred over Integer hooks? Dear all, Attached code is showing a kind of behavior that seems to be a bug. Could anybody confirm that this is indeed a bug, or else point me in the right direction? A work-around may be to implement a single __call__(Object o) method and doing the reflection myself. I am a bit stuck to interfaces within a larger context; such change is deemed to be a last resort. regards - Jorgo Bakker |
From: Jorgo B. <jb...@rs...> - 2004-08-24 15:30:55
|
Dear Clark, Thanks for your comments. Updike, Clark wrote: >This behavior (and the workaround) is pretty clearly documented. > >From: <http://www.jython.org/docs/usejava.html> > I know, and I am not challenging the part of it that you included. Please note, that very document also said: "The possible signatures are sorted in a consistent order that should ensure the appropriate method is chosen first. *TBD: documentation this order!"* Now, it seems to me that for "x=2", "x" is a PyInteger, and the "appropriate method" should be for PyInteger and not Boolean! ... which brings me back to the bug issue. cheers - jorgo ** |
From: Samuele P. <ped...@bl...> - 2004-08-24 19:02:33
|
At 17:30 24.08.2004 +0200, Jorgo Bakker wrote: >Dear Clark, > >Thanks for your comments. > >Updike, Clark wrote: > >>This behavior (and the workaround) is pretty clearly documented. >> >>From: <http://www.jython.org/docs/usejava.html> >I know, and I am not challenging the part of it that you included. Please >note, that very document also said: > > "The possible signatures are sorted in a consistent order that > should ensure the appropriate method is chosen first. *TBD: > documentation this order!"* > >Now, it seems to me that for "x=2", "x" is a PyInteger, and the >"appropriate method" should be for PyInteger and not Boolean! ... which >brings me back to the bug issue. > > >cheers - jorgo >** it's (design) bug sitting there since forever, what you are trying I think is somehow outside the scope of the original dispatch design. Dispatch works pretty well for most practical purposes of calling preexisting Java libraries, which has covered the fact, for a long time (but this is not the first of the sparingly few related reports), that it has subtle issues. The only workaround keeping all the signatures is to fix the method argslist manually. regards PS: I'm not the author of the design dispatch as it stands, and revising it is on the TODO list, also because of bool type introduction in Python. |