If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Singleton is designed for the instance of that class. I think that the call against a .newInstance off the class loader would chain to the constructor, so a private or protected constructor will throw an exception.
To load, its a simple call to Singleton.getInstance();. There is really no way to do this dynamically since you cannot stop an class with a public constructor from instantiating a new record. Any class to be a singleton has to be an instance of a Singleton first. You can call it against a dynamically loaded class though, that's just a simple try/catch and attempt to invoke the Method of getInstance on the class or cast to a Singleton type.

So if I got what you are looking for, your dynamically loaded classes implement singleton. You can load them as so:

The project I am currently working on makes use of the ability to dynamically load classes. Why? I want to allow other developers to develop their own subsystem based on a set of interfaces I already have, and allow users to benefit from it.

I can technically make things very simple for myself and complicated for others, but I do not believe that is the way to go. And though it may sound hypocritical to say this, I would like to uphold certain invariant so that there is design. These invariant might cause the developer to do a LITTLE more work, but it is for the "greater good" so that recompiling the entire source is not required.