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);
}
}
我想定义一个私有构造函数静态 sort() 方法可以调用来创建一个用特定给定数组初始化的哈哈对象。
但是它必须在不分配另一个数组的情况下对其参数数组进行排序,因为公共构造函数已经在分配另一个数组。
问题 1) private haha 如何从 sort() 方法中接收 'a'?如果我做
private Haha(E[] b) // gives error because of different type T & E
{
// skip
}
如果我做
private Haha(T[] b) // gives error too because Haha is class of Haha<E>
{
// skip
}
问题2)如何用特定的给定数组初始化对象
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.
}