avatar
how to do this?# Java - 爪哇娇娃
b*d
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+
+?
avatar
t*e
2
You cannot instantiate it. Generic typed variables are fed through method input
parameters.
avatar
b*d
3
ok then can i instantiate dummy in a non-ctor method?

input

【在 t*******e 的大作中提到】
: You cannot instantiate it. Generic typed variables are fed through method input
: parameters.

avatar
t*e
4
What's you intent? Describe you use case.
avatar
F*n
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 的大作中提到】
: 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+
: +?

avatar
s*k
6
I'm a little confused. Isn't C++ template a "compile-time thing" too?

【在 F****n 的大作中提到】
: There is no way. Unlike C++, Java Generics is a compile-time thing. You
: cannot dynamically create it during time.
:
: in c+

avatar
F*n
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 的大作中提到】
: I'm a little confused. Isn't C++ template a "compile-time thing" too?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。