From: D. J. H. <Dj....@ce...> - 2001-01-16 17:42:51
|
In Java, static methods are /not/ virtual. Overriding will not work the way you expect if called through a base class method -- the derived static method can only be called from derived code. =20 I don't have the exact language spec entry at-hand, but I hit this same exact problem about a year ago (not with Jython, tho). =09=09=09-=3D- D. J. On Mon, 15 Jan 2001, Erlend V [iso-8859-1] B=F8e wrote: > Hi all! >=20 > I'm trying to look into using Jython with JUnit >=20 > in my Class that extends junit.framework.TestCase, i have >=20 > def suite(): > "@sig public static junit.framework.Test suite()" > print "suite called" > return junit.framework.TestSuite("test.SimpleTest") >=20 >=20 > If I dont specify the "@sig", the static suite method is not overridden, = and=20 > if I add the @sig, I get the problem shown below. >=20 > How can a Jython program override a static method? >=20 > Erlend > ------ > [evb@evb unittest]$ jythonc -p test SimpleTest.py > processing SimpleTest >=20 > Required packages: > junit.swingui > junit.framework > =20 > Creating adapters: > =20 > Creating .java files: > SimpleTest module > SimpleTest extends junit.framework.TestCase > =20 > Compiling .java to .class... > Compiling with args: ['/usr/local/ibmjdk1.3/bin/javac', '-classpath',=20 > '/usr/local/jython-2.0b2/jython.jar:.::/usr/local/ant/ant/lib/ant.jar:/us= r/local/JacORB1_1/classes:/usr/local/JacORB1_1/lib/idl.jar:/usr/local/JacOR= B1_1/lib/jacorb.jar:/usr/local/jython-2.0b2/jython.jar:/usr/local/junit3.4/= junit.jar:./jpywork::/usr/local/jython-2.0b2/Tools/jythonc:/home/evb/work/p= ython/unittest/.:/usr/local/jython-2.0b2/Lib',=20 > './jpywork/test/SimpleTest.java'] > 1 ./jpywork/test/SimpleTest.java:158: non-static variable this cannot be= =20 > referenced from a static context > PyObject inst =3D Py.jgetattr(this, "suite"); > ^ > Note: ./jpywork/test/SimpleTest.java uses or overrides a deprecated API. > Note: Recompile with -deprecation for details. > 1 error > =20 > ERROR DURING JAVA COMPILATION... EXITING >=20 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users >=20 |