So I'm writing a program in Java after only using C# for a few years and I can't seem to find the answer to this anywhere. When creating a generic<T>
class in C#, if you want to set a variable to the default value of T
, you use default(T)
. Is there the same functionality in Java and if so how would I do it?
Java does not have an equivalent facility. If you want to pass a value to a generic method you must pass it explicitly, even if you're just invoking the type's default constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With