b*d 发帖数: 75 | 1 i have a generic class
class Dummy {
public Dummy() {
}
private T dummy;
}
how to instantiate the dummy field in ctor? how to achieve "new T()" like in c+
+? |
t*******e 发帖数: 684 | 2 You cannot instantiate it. Generic typed variables are fed through method input
parameters. |
b*d 发帖数: 75 | 3 ok then can i instantiate dummy in a non-ctor method?
input
【在 t*******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : You cannot instantiate it. Generic typed variables are fed through method input : parameters.
|
t*******e 发帖数: 684 | 4 What's you intent? Describe you use case. |
F****n 发帖数: 3271 | 5 There is no way. Unlike C++, Java Generics is a compile-time thing. You
cannot dynamically create it during time.
in c+
【在 b*d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : i have a generic class : class Dummy { : public Dummy() { : } : private T dummy; : } : how to instantiate the dummy field in ctor? how to achieve "new T()" like in c+ : +?
|
s*****k 发帖数: 604 | 6 I'm a little confused. Isn't C++ template a "compile-time thing" too?
【在 F****n 的大作中提到】![](/moin_static193/solenoid/img/up.png) : There is no way. Unlike C++, Java Generics is a compile-time thing. You : cannot dynamically create it during time. : : in c+
|
F****n 发帖数: 3271 | 7 Java template variable declaration, (not type parameters in class definition
), does NOT have any impact on compiled binary code. Search for type erasure.
【在 s*****k 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I'm a little confused. Isn't C++ template a "compile-time thing" too?
|