I want to implement this class to receive different types of arrays, like String, int, double, etc:
public class BubbleSort<T extends Comparable<T>> {
private T [] A;
public BubbleSort(T [] A) {
this.A = A;
}
public void bubbleSort() {
for (int i = 0; i < this.A.length; i++) {
for (int j = 0; j < this.A.length - 1; j--) {
if (this.A[j].compareTo(this.A[j - 1]) < 0) {
T aux = this.A[j];
this.A[j] = this.A[j - 1];
this.A[j - 1] = aux;
}
}
}
}
But when I'm creating an object of that class like this:
double A[] = { 3, 2, 4, 6, 7, 1, 2, 3 };
BubbleSort bs = new BubbleSort(A);
I get an error that tell me the constructor of BubbleSort(double[]) is not defined. I think I'm doing something wrong with the generic type class and i need some help.
Cumps.