> if (Class.forName("com.company.package.myclass").newInstance()
> instanceof MyInterface) {
[quoted text clipped - 4 lines]
>
> Can I do the same thing without calling newInstance()?
Class.isAssignableFrom
I believe you can also get away without initialising the class with
Class.forName(String,false,ClassLoader).
Tom Hawtin
Timasmith wrote On 11/13/06 16:56,:
> Hi,
>
[quoted text clipped - 11 lines]
>
> Can I do the same thing without calling newInstance()?
You could use getInterfaces() on the Class object and rummage
through the array it returns.
I'm worried about your use of the word "suboptimal," though.
If you're making so many of these inquiries that optimality is
a concern, you're probably making too many. What is it about
the design that requires you to do this so often?

Signature
Eric.Sosman@sun.com
Timasmith - 13 Nov 2006 22:48 GMT
> You could use getInterfaces() on the Class object and rummage
> through the array it returns.
[quoted text clipped - 6 lines]
> --
> Eric.Sosman@sun.com
It is not so much that I do it so often in the code, I just do it
somewhere which is called a large number of times and I try to avoid
extra object creation where feasible.