From: Stephen T. <ste...@ho...> - 2003-08-06 16:28:40
|
For any Java method whose return type is either the boolean primitive or the Boolean wrapper class, Jython will coerce the returned value into a Python integer (as you've observed). However, the returned value can be coerced back into a Java boolean with the Boolean wrapper class constructor, like so: >>> from java.lang import Boolean >>> t = TestOverload() >>> t.get(Boolean(t.getBoolean())) 'BOOLEAN' Regards, Stephen > -----Original Message----- > From: jyt...@li... > [mailto:jyt...@li...] On Behalf > Of nicola de candussio > Sent: Friday, August 01, 2003 8:51 AM > To: jyt...@li... > Subject: [Jython-users] overloading int and boolean > > > Hello everyone, > > I am sure this very topic has been discussed before but I > could not find any > reference so here it is: > > I have problems calling overloaded java methods from jython > (please note > they are java primitive types) > > Example: > > given the following java class > > public class TestOverload { > > public String get(boolean p){ > return "BOOLEAN"; > } > > public String get(int p){ > return "INT"; > } > > public boolean getBoolean(){ > return false; > } > } > > I understand that calling the get method passing the a > jython boolean > expression returns "INT" because false or true are mapped to > int but I am > confused when I execute > > t= TestOverload () > t.get(t.getBoolean()) > > and I receive "INT" > > Does it mean that the the boolean value of getBoolean is > converted to 0 and > then passed to get as an int? > If yes, is there any way to have the (java) expected behavior? > > Thanks in advance > > Nic |