From: Charlie G. <cha...@gm...> - 2008-11-14 17:53:14
|
On Thu, Nov 13, 2008 at 4:23 PM, Alfonso Reyes <ms...@re...> wrote: > In this case he return type > would be Sphere and the method bounce(). How could we resolve this in > Jython? > > class Sphere { > int number = 10; > double diameter = 3.5; > double weight = 146.0; > String material = " steel"; > } > > class BeachBall { > Sphere bounce() { > return new Sphere(); > } > } > > public class MethodTyped { > public static void main(String[] args) { > BeachBall b = new BeachBall(); > double anyEq = b.bounce().weight * b.bounce().diameter + > b.bounce().material.length(); > System.out.println(anyEq); > > } > } I'm not sure I understand the problem. Jython does its typing at runtime, so there's no need for casting anything. If I make BeachBall and the fields on Sphere public, I can run the following code in Jython to do the same thing as your main: b = BeachBall() print b.bounce().weight * b.bounce().diameter + len(b.bounce().material) The only thing I needed to change was to use len to get the length of the string, since it's exposed as a Python unicode object. Are you asking how to access package protected fields and methods from Jython? That's currently only possible by setting the system property respectJavaAccessibility to false. You can get to protected items by subclassing, but that's about it. Charlie |