Can getA
and getB
be combined into a single interface method?
For example:
interface ProvidesIndex {
Integer getIndex();
}
Now, you can simply call getIndex
, and your method signature will be:
public Integer getHighestIndexValue(List<? extends ProvidesIndex> list)
As a side note, if you define your interface to extend Comparable<ProvidesIndex>
i.e.:
interface ProvidesIndex extends Comparable<ProvidesIndex>
Then you can use Collections.max
directly on the initial list:
List<ProvidesIndex> list = new ArrayList<ProvidesIndex>();
list.add(new ObjectA());
list.add(new ObjectB());
Integer max = Collections.max(list).getIndex();