I'm moving from C# to java and I'm having troubles with the basics. I'm expecting a variable in my method of type Date and I need to check if the Date has been set or not. How do I do that in Java? using ,equals or == ??
Thanks a lot!
I suspect you want:
public void foo(Date date) {
if (date != null) {
// Use date here
}
}
Note that unlike DateTime
in .NET, java.util.Date
is a class (and therefore a reference type)... Java doesn't have "custom" value types.
Also note that that's not quite the same as whether or not the variable has been "set". For example:
Date date = new Date();
date = null;
Would you consider that variable to be "set" or not? It's set to have a null reference as its value. I suspect you want to know whether the variable has a value referring to an object, but that's not quite the same thing.
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