I would like to limit the compatible types of a method's input to a collection of a certain classes sub classes. However, I would only like to allow the first level down of the sub-classes to be accepted. For instance the class 'shape' has a variety of sub-classes eg. 'rectangle','circle','triangle'. Now 'rectangle' has it's own subclass 'square' so how would I limit the accepted collections to only accept the hierarchical level of sub-classes comprising of rectangle, circle and triangle without accepting square?
0 shape
/ | \
1 rectangle circle triangle
|
2 square
I know that to encompass all of the sub-classes of shape and their sub-classes I would do the following:
public void methodName(List<? extends shape>){ ... }
However, how would i restrict it to only one level of sub-classes down from shape? i.e ( only rectangle, circle, triangle )