From: Byrd, W. <Wil...@co...> - 2001-01-25 17:12:37
|
I have run into some surprising behavior of Java Integer objects while using jython: public class Test { public void foo(Integer I) { System.out.println("Called with an Integer."); } public void foo(int i) { System.out.println("Called with an int."); } public static void main(String[] args) { ... initialize PythonInterpreter ... myInterpreter.exec("test = Test()"); myInterpreter.exec("test.foo(Integer(1))"); myInterpreter.exec("test.foo(2)"); } } Expected output: Called with an Integer. Called with an int. Actual output: Called with an int. Called with an int. I have noticed similar behavior with Double objects. What am I doing wrong? How can I keep Integer and Double objects from being converted to Java primitives? Also, why does the following call to equals() on an Integer object... myInterpreter.set("myInteger", new Integer(1)); myInterpreter.exec("myInteger.equals(Integer(1))"); ...result in an exception? Exception in thread "main" Traceback (innermost last): File "<string>", line 1, in ? AttributeError: 'int' object has no attribute 'equals' Note that the following version works just fine: myInterpreter.exec("myInteger = Integer(1)"); myInterpreter.exec("myInteger.equals(Integer(1))"); Thanks. Regards, Will |