Finding the nearest common superclass (or superinterface) of a collection of classes

后端 未结 6 1820
青春惊慌失措
青春惊慌失措 2020-12-08 14:23

Given a collection of classes, what\'s the best way to find the nearest common superclass?

E.g., given the following:

interface A {}
interface B {}
         


        
6条回答
  •  有刺的猬
    2020-12-08 14:57

    I am also facing this problem right now. I only need the answer on the superclass level. Basically I found it best to only do a O(n) walk through.

    You have to define an operation Cmin(A, B) giving you the nearest superclass of class A and class B.

    Since Cmin results in a class itself you can use this algorithm:

    Result = Cmin Ai | (ai elementIn classes).

    gives you O(n).

    But remember Java makes a distinction in types being interfaces or classes.

提交回复
热议问题