I’m stuck. Coming from C++ I thought this would simply work, but it does not. Can you please give me an advice? I will try to not end up with kind of creation method in each class used for T.
public class A<T>{
private T t_;
public A(){
t_ = new T(); //error
}
}
Also i don’t want to have constructor looking like: A(Class classT){ …
Ideally i would like to have something like this c++ code.
template<class T>
class A{
private:
T t_;
public:
A(){}
};
Thanks for help.
You cannot do such things in Java. Read about type erasure: http://docs.oracle.com/javase/tutorial/java/generics/erasure.html