Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个私有成员,它是一个泛型类型的数组,在我的构造函数中,我有一个参数来设置这个数组的大小。如何将我的私有数组设置为构造函数参数指定的大小?
这就是我所拥有的:
private T[] hashTable; public HashTable(int initSize){ // set hashTable size here }
此解决方案需要从Object[].
Object[]
public class HashTable<T> { private T[] hashTable; public HashTable(int initSize){ // set hashTable size here hashTable = (T[]) new Object[initSize]; } }