views:

186

answers:

1

I would like to implement a template which contains an array of the template Type. Is there a way to do something similar to what I have outlined in my sample code? The problem is in the line where this.foo is assigned a new array of the template type.

class Classname<T>
{
  T[] foo
  Classname()
  {
    this.foo=new T[128];
  }
}
+3  A: 

This doesn't work, and here is a good answer that explains why. But, practically spoken, an Arraylist is a good replacement, because it basically wraps an array in a list object.

Edit

This question is even closer to your problem

Andreas_D