Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > jython type coercion to interface type

Reply
Thread Tools

jython type coercion to interface type

 
 
Harald Kirsch
Guest
Posts: n/a
 
      06-25-2003
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
 
Reply With Quote
 
 
 
 
Harald Kirsch
Guest
Posts: n/a
 
      06-26-2003
Ype Kingma <> wrote in message news:<3ef9f6ab$0$141$4all .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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open source type coercion framework? Simon Brooke Java 1 06-27-2010 05:04 PM
FW: [Jython-users] Jython Licensing Question Pinegar, Kent T Python 0 07-24-2008 01:38 PM
FW: [Jython-users] ERROR : parsing xml in jython Divya Prakash Python 0 12-19-2006 02:49 PM
[Jython-users] ANN: SPIRO - a cPython->Jython bridge (amongst otheruses) David McNab Python 0 04-09-2004 10:20 AM
list() coercion Ian Bicking Python 5 07-18-2003 03:18 AM



Advertisments