From: <bc...@wo...> - 2001-01-30 10:46:24
|
[Will] >I have run into some surprising behavior of Java Integer objects while using >jython: ><example snipped> >What am I doing wrong? How can I keep Integer and Double objects from being >converted to Java primitives? [Finn] > You can't. The eagerness with which Jython converts the java.lang.* > wrapper classes to instances of native python classes have been > discussed previousely: > > http://mail.python.org/pipermail/jpython-interest/1999-December/002590.html [Ben Hutchison] >My main concern is: will this obstruct the use of Java APIs which require Boolean >parameters? In the example William gives the expected method is not invoked. Will >developers using Jython to script or integrate existing Java systems encounter >problems; either hard to find bugs, or method signatures that cant be invoked? > >> It is basicly the same problem you have re-discovered. I'm still not >> convinved that it is a net win to reduce this eagerness. >> >> http://mail.python.org/pipermail/jpython-interest/1999-December/002596.html > >From the above article, Finn Bock wrote: > > One of the downsides of this patch, is that the simple if statement > below will no longer work. I am afraid to think about the > incompabilities this change will introduce in existing jpython > programs. > > if not lang.Boolean.FALSE: > print "FALSE" > >Equivalently, the statement below is not legal Java. So? <0.7 wink> >Is there need to support semantics that arent in Java? Yes. One of the problem, as I see it, is that we can evaluate the booleaness of a lot of objects. Testing lists and dicts are done all the time: l = ['a'] if l: print "list is not empty" Since that is possible, common sense dictate that testing a j.l.Boolean in an "if" statement should actually test the value the Boolean is wrapping. The same extends to arithmetic on j.l.Number subclasses, where is should still be possible to add a j.l.Short and 42 together. >I cant imagine many developers using expressions >similar to above, since they couldnt in Java anyway. > > if (! Boolean.FALSE) {} This lack of flexibility in java will not convince me that jython don't need it either <wink>. I said that I will not spearhead this change. I think jython can be modified in such a way that the wrapper objects are keept as java objects but still maintain their usefullness when used from a python script. It's just not something I will do. >As I understand the issues, I *think* I prefer a less eager conversion policy, >but would be happy to hear more counter-arguments. I would be more happy to see a patch <wink>. regards, finn |