jython type coercion to interface type

Discussion in 'Python' started by Harald Kirsch, Jun 25, 2003.

  1. 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
     
    Harald Kirsch, Jun 25, 2003
    #1
    1. Advertising

  2. 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
     
    Harald Kirsch, Jun 26, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Bicking

    list() coercion

    Ian Bicking, Jul 17, 2003, in forum: Python
    Replies:
    5
    Views:
    351
    Ian Bicking
    Jul 18, 2003
  2. David McNab
    Replies:
    0
    Views:
    499
    David McNab
    Apr 9, 2004
  3. Divya Prakash
    Replies:
    0
    Views:
    443
    Divya Prakash
    Dec 19, 2006
  4. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    356
    Pinegar, Kent T
    Jul 24, 2008
  5. Simon Brooke

    Open source type coercion framework?

    Simon Brooke, Jun 27, 2010, in forum: Java
    Replies:
    1
    Views:
    389
    Jeff Higgins
    Jun 27, 2010
Loading...

Share This Page