| Author |
Executing Singleton class with Custom Class Loaders
|
sriram sundararajan
Ranch Hand
Joined: Apr 08, 2003
Posts: 43
|
|
Hi All,
I am trying to develop a custom class loader to load a singleton class.
Below are the code snippets involved.
I compiled Singleton1.java and got the class file in the same folder.
When i am trying to run ChkSingletonCL.java, i am getting a java.lang.IllegalAccessException
@ line 45. How can I run the Singleton class with custom class loader.
The Error msg. is "java.lang.IllegalAccessException: Class sripy.classLoader.ChkSingletonCL can not access a member of class Singleton1 with modifiers "private"
Basically i want to test the Singleton behaviours in the custom class loaders.
Singleton1.java
ChkSingletonCL.java
regards
sri
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
Question too difficult for "beginning". Moving thread.
|
 |
Ireneusz Kordal
Ranch Hand
Joined: Jun 21, 2008
Posts: 423
|
|
Hi,
first, your Singleton1 class doesn't have a getName() method, so you must declare it first before invoking it from the main().
Second, constructor Singleton() is private, therefore you cannot use Class.newInstance() method because it works only for public default constructor.
Third, method getName() is private, so you cannot use class.getMethod(name,...) method because it works only for public methods.
See javadoc for details.
Try this code:
|
 |
sriram sundararajan
Ranch Hand
Joined: Apr 08, 2003
Posts: 43
|
|
Hi Ireneusz,
Thanks i can now able to call the singleton class. I think its high time for me to tune up my reflection knowledge. Thanks again.
|
 |
 |
|
|
subject: Executing Singleton class with Custom Class Loaders
|
|
|