I want to write equivalent Java code for C # code.
My C # code is as follows:
public abstract class A<T> where T : A<T>, new() { public static void Process() { Process(new T()); } public static void Process(T t) {
The Java equivalent of my code is as follows.
public abstract class A<T extends A<T>> { public static <T extends A<T>> void process() { process(new T());
Here, the syntax "new ()" in the class declaration causes derived classes to write a default constructor that allows you to call "new T ()" from the base class. In other words, when I use the base class, I am sure that the derived class will have a default constructor, so I can instantiate the derived class object from the base class.
My problem is in Java: I cannot create an instance of a derived class object from a superclass. I get the error "Cannot instantiate the type T" for calling "new T()" . Is there any C # similar way in Java or should I use something like a prototype and cloning pattern?
Mehmet AtaΕ
source share