Answer the question
In order to leave comments, you need to log in
Generic method that returns an instance of a new class?
Good afternoon.
Please help me understand generic methods.
There is such a design of classes.
class A {
public A(String a) {
}
}
class B extends A {
public B(String b) {
super(b);
}
}
class C extends A {
public C(String a) {
super(a);
}
}
public <T extends A> T addRandomCart(Class<T> type) {
String element = "element";
A ps = new A(element);
return (T) ps;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question