jython type coercion to interface type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harald Kirsch

    jython type coercion to interface type

    How would I call a java constructor which takes a java.lang.CharS equence
    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.CharS equence". Then

    x = X(CharSequence( "bla"))

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

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

    Harald Kirsch
  • Harald Kirsch

    #2
    Re: jython type coercion to interface type

    Ype Kingma <ykingma@access forall.nl> wrote in message news:<3ef9f6ab$ 0$141$e4fe514c@ dreader5.news.x s4all.nl>...[color=blue]
    > Harald Kirsch wrote:[/color]
    [snip][color=blue][color=green]
    > > class X {
    > > public X(CharSequence s) { ... }
    > > }[/color][/color]
    [snip][color=blue][color=green]
    > > x = X(CharSequence( "bla"))
    > >
    > > and got "can't instantiate interface (java.lang.Char Sequence)"[/color][/color]
    [color=blue]
    > Could you try this:
    >
    > from java.lang import String
    >
    > x = X(String("bla") )
    >[/color]
    Yes, this worked.

    Thanks,
    Harald

    Comment

    Working...