Filling and sorting the list <? expands T & S>
I am creating a set of custom swing components that implement various properties, such as requiredor tabIndex. I am having problems trying to populate Listvarious custom components and then sort the list based on tabIndexeach component.
As I try to do this, it is to implement my components using an interface Indexedthat implements a single method getIndex(). Then sort with IndexedComparator.
My classes are:
indexed:
public interface Indexed {
public int getIndex();
}
IndexedComparator:
public class IndexedComparator implements Comparator<Indexed> {
@Override
public int compare(Indexed o1, Indexed o2) {
return o1.getIndex() - o2.getIndex();
}
}
WWTextField:
public class WWTextField extends JTextField implements Indexed, FocusListener {
private boolean required;
private int tabIndex;
...
@Override
public int getIndex() {
return tabIndex;
}
}
NewJFrame:
public class NewJFrame extends JFrame {
List<? extends Component & Indexed> list = new ArrayList<>();
IndexedFocusTraversalPolicy policy = new IndexedFocusTraversalPolicy();
public NewJFrame() {
initComponents();
list.add(wWTextField1);
list.add(wWTextField2);
list.add(wWTextField3);
list.add(wWTextField4);
list.add(wWTextField5);
list.add(wWFormatedTextField1);
list.add(wWFormatedTextField2);
Collections.sort(list);
policy.populateComponents(list);
this.setFocusTraversalPolicy(policy);
}
}
Edit: I forgot to post the real question. Why is my implementation
List<? extends Component & Indexed> list = new ArrayList<>();
Job? When I try to compile, I get the following errors:
NewJFrame.java:22: error: > expected
NewJFrame.java:22: error: ';' expected
NewJFrame.java:22: error: illegal start of type
+1