In the default construction, what value should be assigned to a generic type field?

class claz<T> { T information; claz(){} //??? } 
  • null no longer in fashion? - ArchDemon Nov.
  • public claz(T arg) { information = arg; } public claz(T arg) { information = arg; } - Alexey Shimansky
  • @ Alexey Shimansky, and if there are no arguments in the constructor, how did the author portray? - ArchDemon Nov.
  • @ArchDemon and if you do not write, will null be assigned an automaton? - user229181

1 answer 1

In the default constructor, it will not be possible to assign any specific value (of a parameterized type ) to a generic other than null .

And in general, it is not necessary to initialize the generic in the default constructor; it will be so, without explicit initialization, null (like any object type).