I have a generic class I'd like to convert from C# to Java. The class starts off this way:
public class StackImplementationUsingDynamicArray<T>
{
private T[] _array = new T[10];
}
I can't seem to get the equivalent Java code for the declaration. This code at least compiles (with a warning) but throws a runtime exception:
public class StackImplementationUsingDynamicArray<T>
{
private T[] _array = (T[])Array.newInstance (StackImplementationUsingDynamicArray.class, 10);
}
Is it possible to do this in Java? What should the code be? Thanks in advance for any pointers.