468,471 Members | 1,681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,471 developers. It's quick & easy.

jython type coercion to interface type

How would I call a java constructor which takes a java.lang.CharSequence
as argument. Say, the java class goes like this

class X {
public X(CharSequence s) { ... }
}

In the jython interpreter I tried along the lines of

x = X("bla")

and got "1st arg can't be coerced to java.lang.CharSequence". Then

x = X(CharSequence("bla"))

and got "can't instantiate interface (java.lang.CharSequence)"

Is there a way to typecast String to CharSequence or, mor generally,
a type to a supertype or interface?

Harald Kirsch
Jul 18 '05 #1
1 3477
Ype Kingma <yk*****@accessforall.nl> wrote in message news:<3e*********************@dreader5.news.xs4all .nl>...
Harald Kirsch wrote: [snip]
class X {
public X(CharSequence s) { ... }
} [snip] x = X(CharSequence("bla"))

and got "can't instantiate interface (java.lang.CharSequence)"

Could you try this:

from java.lang import String

x = X(String("bla"))

Yes, this worked.

Thanks,
Harald
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Harald Kirsch | last post: by
21 posts views Thread by Batista, Facundo | last post: by
6 posts views Thread by Dave Benjamin | last post: by
4 posts views Thread by angel | last post: by
6 posts views Thread by Mike Wimpe | last post: by
12 posts views Thread by Mark Fink | last post: by
669 posts views Thread by Xah Lee | last post: by
59 posts views Thread by peter.tornqvist | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.