Integer[] intArray = new Integer[] {1,2,3,4};
Haha.sort(intArray);
public class Haha<E extends Comparable<? super E>> implements B<E>
{
private E[] array;
public Haha()
{
array = (E[]) new Comparable[10];
}
private Haha( ??? )
{
???
}
public static <T extends Comparable<? super T>> void sort (T[] a)
{
Haha(a);
}
}
I want to define a private constructor static sort() method can call to create a Haha object initialized with a particular given array.
But it has to sort its argument array without allocating another array because public constructor is already allocating another array.
problem 1) How can private Haha receive 'a' from sort() method?? If I do
private Haha(E[] b) // gives error because of different type T & E
{
// skip
}
If I do
private Haha(T[] b) // gives error too because Haha is class of Haha<E>
{
// skip
}
problem 2) How to initialize object with a particular given array
private Haha( ??? b ) // if problem 1 is solved
{
array = b; // is this right way of initializing array, not allocating?
// It also gives error because sort() is static, but Haha is not.
}
B? Is it relevant to the question?