Hi Jython Makers,
 
I was struck by this the other day when I was implementing the "Commentaries" feature in jyleo.  I had a class/objects that needed to be viewable in a Swing widget.  The class could not be subclassed from a Java Object because:
1. It needed to be pickled
2. It needed to be instantiable in CPython
 
I implemented toString so it would give a correct representation in the Swing widget.  But to my, I guess, surprise it showed something like:
<instance 15 >
 
instead of:
the-text-representation-of-object
 
At this point I had to create a wrapper that subclassed java.lang.Object to get my toString behavior.  This struck me as inconvenient, which is why Im posting this question.  Should not a pure jython class when implementing a matching method in java.lang.Object become the method to call when operated on in Java?  I dont have an answer on my question, just the sense that it would be convenient.  A class like this
class x:
...def toString( self ):
.....return "X text"
 
if called in Java, like so:
jython_instance.toString()
should return:
"X text"
instead of:
<instance of something 15>
I guess toString is just the example.  Maybe hashCode should do the same.  Would it not be possible in the Java object to have the corresponding method check and see if there is a Jython implementation and call that as the method?  Or is it the case than when faced with such an object, I should consider it to have 2 different toString methods.  Each one existing in a different universe.
 
gotta run,
leouser

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com