Thanks Jeff. I see your and finn's replies ( at
http://aspn.activestate.com/ASPN/Mail/Message/1580322
) and wonder why doesn't Jython reflect on Java String
and find out all the classes and interfaces it inherits, and
test if c is an instance of any of them, instead of hard-
wiring it like:
> if (c == String.class || c == Object.class || c == Serializable.class)
 
ma0hai

Jeff Emanuel <JEmanuel@lgc.com> wrote:

Please look in the mailing list archives for a recent
discussion on converting jython strings to CharSequence.
The same issues apply.


-----Original Message-----
From: maohai huang [mailto:lists_mh@yahoo.com]
Sent: Tuesday, April 22, 2003 4:47 PM
To: jython-users@lists.sourceforge.net
Subject: [Jython-users] Jython string coercion to java String


hi, I have this java class

public class Foo {
public void com(java.lang.Comparable c) {
}
}

in jython I want to pass it a jython string:

jython
Jython 2.1 on java1.4.1_01 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import Foo
>>> f=Foo()
>>> f.com('as')
Traceback (innermost last):
File "", line 1, in ?
TypeError: com(): 1st arg can't be coerced to java.lang.Comparable
>>>

I would expect jython to know that Java String class
implements the java.lang.Comparable interface, and
does some coercion so that it would work, just
as if I typed this:
>>>from java.lang import String
...
>>>f.com(String('as'))

Am I missing something? sorry if this is an old question.
thanks
ma0hai






Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.