access a static class field

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

access a static class field

Bugzilla from jasonzhang2002@gmail.com
Hi,

Suppose I have a Class A which does not have public constructor, how can I access the class's public static field?

I tried this

Class a=getClass("A")
a.members=new ArrayList();

but it does not work.

Thanks


--
-jiesheng
Reply | Threaded
Open this post in threaded view
|

Re: access a static class field

Daniel Leuck
Hi Jason,

It works the same way it would in Java.  If you have a class called
MyClass you would access it using the class name.  The visibility of the
constructors (public, private, etc.) is irrelevant because you are not
instantiating an instance of the class.  If the class is not declared
locally or included as a default import, you need to ensure it is included
in your classpath and import it in your script.

import org.jason.MyClass;

MyClass.members=new ArrayList();

I suggest reading:
http://www.beanshell.org/manual/quickstart.html#Quick_Start

For information re: classpaths, importing, etc. I would pick up Pat's book
http://www.amazon.com/gp/product/0596002858/104-3432844-2702302?n=283155

Daniel Leuck
http://www.ikayzo.com
http://www.javaui.net

> Suppose I have a Class A which does not have public constructor, how can I
> access the class's public static field?
>
> I tried this
>
> Class a=getClass("A")
> a.members=new ArrayList();
>
> but it does not work.
>
> Thanks




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users