If I have a Class clazz object, is it possible to determine if it implements Comparable without calling newInstance() against it?
This is the code I currently have, but I'd like to do the same thing without creating a variable that will immediately be thrown away.
private boolean implementsComparable(Class clazz)
{
try
{
if (clazz.newInstance() instanceof Comparable)
{
return true;
}
}
catch (Exception ex)
{
// @TODO something about NPE's
// ignore all exceptions here
}
return false;
}
Thank you.