|
From: Brian Z. <bri...@ya...> - 2001-06-30 00:37:23
|
That's exactly like the example I gave. You get the Object back (you know it's actually a String, right?), then you can just pass the instance directly to the xml-rpc method expecting a String. No cast needed. Because you call the method from Jython, there won't be any compilation error. Runtime, if it's really a String, no problem; if not, it will raise AttributeError for any String method get invoked. -Brian ----- Original Message ----- From: "Roman Milner" <ro...@sp...> To: "Brian Zhou" <bri...@ya...> Cc: <jyt...@li...> Sent: Friday, June 29, 2001 5:21 PM Subject: Re: [Jython-dev] casting > >>>>> "BZ" == Brian Zhou <bri...@ya...> writes: > > BZ> In dynamic languages like Python/Smalltalk/Scheme, you usually > BZ> don't need cast. Because "the methods a particular instance > BZ> can perform" becomes the type of the instance, it's not as > BZ> important which class that instance actually belongs. At > BZ> instantiation time, "all the methods the instance can perform" > BZ> is determined. At runtime, you either can call the method or > BZ> you get an AttributeError. > > What if you need to pass an object to a java method that requires it > to be cast to a different java type? > > What if one java method gives me an Object back, but it is actually a > String. I have another java method that requires a String argument. Is > there a way to do that cast in jython? > > I ran in to this when trying to use the Java xml-rpc library from > jython. > > ^Roman > |