Not quite.
Class.forName() is declared to return Class<?>, but you want Class<Facade>.
[...]
>> If not, what?
> You'll still need a cast:
> Class<Facade> clazz = (Class<Facade>) Class.forName(classPath);
> Facade facade = clazz.newInstance();
I prefer to use a bit type-safer version of the above:
Class<? extends Facade> clazz
= Class.forName(classPath).asSubclass(Facade.class);
Facade facade = clazz.newInstance();
piotr
Thomas Fritsch - 06 Nov 2007 13:26 GMT
>> You'll still need a cast:
>> Class<Facade> clazz = (Class<Facade>) Class.forName(classPath);
[quoted text clipped - 5 lines]
> = Class.forName(classPath).asSubclass(Facade.class);
> Facade facade = clazz.newInstance();
Granted! I prefer yours, too.

Signature
Thomas
Adam Lipscombe - 06 Nov 2007 14:38 GMT
Groovy! Many thanks....
Adam
Daniel Pitts - 06 Nov 2007 16:11 GMT
> [...]
>
[quoted text clipped - 10 lines]
>
> piotr
Not to mention that this is more correct.
The Class instance itself is the MyClass, not Facade, so Class<Facade>
is just plain wrong, where as Class<? extends Facade> is accurate.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>