Re: A newbie question related to using bsh
Alexey Zinger <inline_four-/[email protected]> Wed, 5 Aug 2009 09:00:15 -0700 (PDT)
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
Dynamically, the JVM doesn't care about the type of reference to any object= . And of course, each object knows its own type anyway. If you wish to ex= ecute a set of scripts not knowing what their return objects will be, you'l= l just have to put them in some collection of Object: Set<?>/ List<?>. Presumably, since you expect to do something with those result objects, you= 'll have some idea about their types. So you can then cast as you retrieve= them from said collection: List<?> myResults =3D ...; Number howMany =3D (Number)myResults.get(0); Date when =3D (Date)myResults.get(1); Make sense? Alexey 2001 Honda CBR600F4i (CCS) 1992 Kawasaki EX500 http://azinger.blogspot.com http://bsheet.sourceforge.net http://wcollage.sourceforge.net ________________________________ From: Neo Anderson <javadeveloper999-/[email protected]> To: Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Sent: Wednesday, August 5, 2009 11:40:52 AM Subject: Re: [Beanshell-users] A newbie question related to using bsh But how if those scripts would return variant types? For instance, there ar= e 3 bsh scripts I want to collect. So in the Java application I might scan = the dir and use = for(...){ Object result =3D bsh.Interpreter().source(BshFileNames); } So the result object would be different kind of type e.g. class A, class B = and Class C. = Is there any chance that I can cast them dynamically? Thanks to reply my question. --- On Wed, 5/8/09, KUN LI <[email protected]> wrote: > From: KUN LI <[email protected]> > Subject: RE: [Beanshell-users] A newbie question related to using bsh > To: javadeveloper999-/[email protected], "beanshell - users" <beanshell-users@li= sts.sourceforge.net> > Date: Wednesday, 5 August, 2009, 3:34 PM > = > = > = > #yiv1311021128 .hmmessage P > { > margin:0px;padding:0px;} > #yiv1311021128 { > font-size:10pt;font-family:Verdana;} > = > = > = > You can use "Collection" which can be a > "List" or "Vector". > = > Example: > = > Collection<A> results =3D new Arraylist(); > = > results.add(result); > = > Kun LI > = > = > = > = > > Date: Wed, 5 Aug 2009 15:22:02 +0000 > > From: javadeveloper999-/[email protected] > > To: Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > > Subject: [Beanshell-users] A newbie question related > to using bsh > > = > > = > > I read the doc at > http://www.beanshell.org/examples/callscript.html. But this > arises me a question. How can I cast the result object into > the type I want? For instance, in the script I finally have > type A created, then in the Java application I obtained > using the following statement > > = > > Object result =3D new > bsh.Interpreter().source("myscript.bsh"); > > = > > I can cast result to A if I only have one script e.g. > > = > > A a =3D (A) result; > > = > > However, how if I want to collect many scripts once > and then cast all object collected into type desired? > > = > > Is there any way I can achieve this? > > = > > Thanks for help. > > = > > = > > = > > = > > = > > = > > > -------------------------------------------------------------------------= ----- > > Let Crystal Reports handle the reporting - Free > Crystal Reports 2008 30-Day = > > trial. Simplify your report design, integration and > deployment - and focus on = > > what you do best, core application coding. Discover > what's new with = > > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > _______________________________________________ > > Beanshell-users mailing list > > Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > > > https://lists.sourceforge.net/lists/listinfo/beanshell-users > = > Discutez sur Messenger o=F9 que vous soyez ! Mettez > Messenger sur votre mobile ! = > = = ---------------------------------------------------------------------------= --- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day = trial. Simplify your report design, integration and deployment - and focus = on = what you do best, core application coding. Discover what's new with = Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Beanshell-users mailing list Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/beanshell-users = ---------------------------------------------------------------------------= --- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day = trial. Simplify your report design, integration and deployment - and focus = on = what you do best, core application coding. Discover what's new with = Crystal Reports now. http://p.sf.net/sfu/bobj-july