I’m failing to create this class hirerarchy that includes a generic that is comparable. What am I missing here? This throws an error.
public class Generics <T extends Comparable<T>>
extends Parent<T extends Comparable<T>> {
ArrayList<T> ar;
public Generics() {
ar = new ArrayList<>();
}
@Override
public void add(T elt){
ar.add(elt);
}
}
And the parent class is:
public class Parent <T extends Comparable<T>>{
int size =0;
public Parent(){
size=0;
}
public void add(T elt){
size++;
}
}
Try “Extract Superclass” on the following. I tried extracting the ArrayList and the add(T elt). This is on the following config:
Product Version: NetBeans IDE 7.2 (Build 201207171143)
Java: 1.7.0_07; Java HotSpot(TM) 64-Bit Server VM 23.3-b01
System: Linux version 3.2.0-30-generic running on amd64; UTF-8; en_US (nb)
public class Generics <T extends Comparable<T>> {
ArrayList<T> ar;
int size;
public Generics() {
ar = new ArrayList<>();
size = 0;
}
public void add(T elt){
ar.add(elt);
size++;
}
}
Try out this