Message550
A python class inheriting from JPanel and a java
interface can't be instantiated because jython can't
find one of the methods required by the interface. I
tried to simplify the example below to use simple
classes, but the error went away, so I suppose the
complexity of JPanel plays a role. Example:
Test.java:
import java.awt.Container;
public interface Test {
Container getParent();
}
test.py:
import java.awt.Component
import java.awt.Container
import javax.swing.JPanel
import Test
class Error1(javax.swing.JPanel, Test):
pass
class Error2(javax.swing.JPanel, Test):
def getParent(self):
return None
class OK1(java.awt.Container, Test):
pass
class OK2(java.awt.Component, Test):
pass
Error1() # doesn't work
Error2() # doesn't work
OK1() # works
OK2() # works
Neither Error1 nor Error2 can be instantiated; the
error message is
AttributeError: abstract method "getParent" not
implemented
Classes OK1 and OK2 can be instantiated without an
error.
I believe that the code is correct because the
getParent() method inherited via java.awt.Component ->
java.awt.Container -> javax.swing.JComponent ->
javax.swing.JPanel should satisfy the interface
requirement. Indeed, a class analogous to Error1
compiles and runs fine under java. Working around this
problem is difficult because even Error2 fails.
This problem exists under jython 2.0 and jython 2.1
with either Sun JDK 1.3.1 or IBM jikes 1.13 and
IBMJava2-13 runtime.
Yours,
Michael
|
|
Date |
User |
Action |
Args |
2008-02-20 17:17:00 | admin | link | issue504972 messages |
2008-02-20 17:17:00 | admin | create | |
|