R
Robert Dodier
Hello,
Given a collection of classes, how can I find their nearest common
superclass?
It seems like it would be simple enough -- maybe something
which iterates over a pair-wise comparison such as this:
static Class commonSuperclass (Class c1, Class c2)
{
if (c1.isAssignableFrom (c2)) return c1;
if (c2.isAssignableFrom (c1)) return c2;
return commonSuperclass (c1.getSuperclass (), c2.getSuperclass ());
}
But it seems likely there are pitfalls which would affect a naive
implementation. So I'm hoping this is a wheel which doesn't need
reinvention today. Any info is appreciated.
Robert Dodier
Given a collection of classes, how can I find their nearest common
superclass?
It seems like it would be simple enough -- maybe something
which iterates over a pair-wise comparison such as this:
static Class commonSuperclass (Class c1, Class c2)
{
if (c1.isAssignableFrom (c2)) return c1;
if (c2.isAssignableFrom (c1)) return c2;
return commonSuperclass (c1.getSuperclass (), c2.getSuperclass ());
}
But it seems likely there are pitfalls which would affect a naive
implementation. So I'm hoping this is a wheel which doesn't need
reinvention today. Any info is appreciated.
Robert Dodier