Hi John,
On Fri, 31 Aug 2001, John Goerzen wrote:
> Hi,
>
> I'm trying out Jython for the first time but the documentation have
> not covered this scenario:
>
> I want to make a class that is callable by Java, that is a child only
> of java.lang.Object, whose constructor can take 0 or 1 arguments.
>
> There seems to be no way to specify two @sig lines.
True, but jythonc doesn't require multiple sigs.
> import java
>
> class Foo(java.lang.Object):
> def __init__(self, arg=None):
> """@sig public Foo()
> @sig public Foo(String arg)"""
> if arg:
> print arg
> else:
> print "No arg passed"
You don't need multiple @sigs, jythonc figures it out for you. In your
code example, the only @sig you need is "@sig public Foo(String arg)". If
you take a peek at Foo.java, you will see that you also get an empty
constructor for free.
Additionally, if you have two default args, jythonc adds constructors
for no args, 1 arg, and 2 args.
for example:
import java
class Foo(java.lang.Object):
def __init__(self, arg1=None, arg2=None):
"@sig public Foo(String arg1, String arg2)"
print arg1, arg2
With that one @sig string, you can call the constructors from Java:
test t = new test();
test t = new test("bar");
test t = new test("bar", "zab");
-rb
|