Hi Jeff, thanks. This is a good summary of the cleaner Jython way to
get/set "properties" .. which are basically instance variables from the
Java point of view.
But my interest was sorta the reverse: how to make Jython classes use
its nifty properties facility to implement the Java getter/setter
protocol automatically. (This is only necessary if your Jython
instances are being used by Java frameworks which expect the get/set
style. I have this a LOT!)
In other words, I'd like to avoid building get/set methods in my Jython
class instances which are being used by a Java program as a "bean".
For this to work, there would have to be something that automatically
built get/set methods for classes (as Groovy does), or there would have
to be a run-time mechanism that sees a getFoo/setFoo call and converts
it to a simpler property usage.
The whole point is this: Java is way, way too verbose. Groovy and a
few other scripting systems are trying to reduce this to make Java and
its platform independence more approachable by more people. Jython
does this, with the benefit of the rich Python tradition and well
crafted language. Getter/setters are part of the verbosity, Groovy
manages this, thus the natural question: how would Jython deal with
removing this "noise".
Possibly the error handlers could do this? Or we could invent a new
function called "create_get_set_methods"?
On Dec 4, 2004, at 9:55 AM, Jeff Emanuel wrote:
> See jython source org/python/core/PyJavaClass.java
> Owen Densmore wrote:
>> I'm using Jython within a Java framework which uses bean
>> getter/setters. Thus when I build a class in Jython to be used by
>> this framework, I need to build getter/setter methods in the Jython
>> My question is: is there a way to have Jython auto-generate these?
>> Groovy, for example, intercepts getter/setters from Java and
>> automatically converts them to property/attribute requests. I
>> presume because Jython has foo.var abbreviations, it might somehow do
>> a similar thing, removing the need for the annoying getter/setter
>> hand-made code.