I am newbie to java. But I used c++ a lot. I got a class written in c++. Now I need to rewrite the class in java. I got confused about the generic types.
My c++ class is something like this:
//Form, Cmpt are of class type. nCmpt is a integer
template <class Form, class Cmpt, int nCmpt>
class VectorSpace
{
public:
//component array
Cmpt v[nCmpt];
//constructors
VectorSpace();
VectorSpace(const VectorSpace<Form,Cmpt,nCmpt>& m_v);
.....
.....
};
I tried to rewrite it in java, I got problems:
public class VectorSpace<Form, Cmpt, nCmpt>
{
public Cmpt v[];
public VectorSpace()
{
v = new Cmpt[nCmpt];
}
.....
.....
}
I got errors:
**Can't create a generic array of Cmpt.
nCmpt cannot be resolved to a variable.**
Can anyone help this out? How can I use template in java to achieve the same functionality as it was in c++? (I don't want to define an integer variable inside class and use it as an argument in the constructor of my java version).
Thank you.