I'd like to pass a String parameter as "null"
However, this is for the super method in a constructor - so i cannot do
String s = null;
super(s);
I cannot just do
super(null)
as this will result in an ambiguous method call. I don't want to have an instance variable that is null for this either, that seems inelegant.
Is there a way to create a null String?
NB
new String(null) //does not compile
Just do this
super((String)null);
CodeMan posted the correct answer, another solution, move away from null, and consider initializing with Empty string
super("");
this would avoid a null check later.
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