Forums Register Login

How CheckNotNull works

+Pie Number of slices to send: Send
Hi ,

Can anyone please explain me how exactly CheckNotNull works.

Thanks,
Ashwin
+Pie Number of slices to send: Send
 

Ashwin ks wrote:Hi ,

Can anyone please explain me how exactly CheckNotNull works.

Thanks,
Ashwin



Hi Ashwin, Welcome to Java Ranch!
Can you give more context to this? I dont think "CheckNotNull" is from the Java API.
+Pie Number of slices to send: Send
Hi Mohammed,

I m new to java ... i came across a scenario where in the code in if condition check NotNull is used so i want to know how exactly it works.

Thanks for your response Mohammed

Thanks,
Ashwin
+Pie Number of slices to send: Send
 

Ashwin ks wrote:Hi Mohammed,

I m new to java ... i came across a scenario where in the code in if condition check NotNull is used so i want to know how exactly it works.



Can you tell us the reference where you found this usage? Or better post a simple working code. It will help us to clear your doubt easily.


+Pie Number of slices to send: Send
if ((user.equals("customer"))) {
selectRadioButton(USERCUSTOMERRADIO);
enterText(USERCUSTOMERTEXTBOX, name);
} else {
selectRadioButton(USERSUPPLIERRADIO);
enterText(USERSUPPLIERTEXTBOX, name);
}
clickElement(CHANGEBUTTON, DEFAULTWAIT);
}


I want know how use not null in these case.
+Pie Number of slices to send: Send
 

Ashwin ks wrote:

I want know how use not null in these case.



Please use the [code]tags to post your code.

Am not able to see your Use case here- You want to check if the value is not null? Then you could use- <variable> != null, or to check for empty string you could try- <variable>.equals("").
+Pie Number of slices to send: Send
OK thanks a lot
+Pie Number of slices to send: Send
 

mohammed sanaullah wrote:Am not able to see your Use case here- You want to check if the value is not null? Then you could use- <variable> != null, or to check for empty string you could try- <variable>.equals("").



But remember that an empty String ("") is not the same as null.
1
+Pie Number of slices to send: Send
 

Jan Hoppmann wrote:But remember that an empty String ("") is not the same as null.


This sometimes confuses people. A good way to think of the difference is an empty string is a box with nothing in it. A null string means you don't even have a box.
+Pie Number of slices to send: Send
 

fred rosenberger wrote:
This sometimes confuses people. A good way to think of the difference is an empty string is a box with nothing in it. A null string means you don't even have a box.



Nice example!
+Pie Number of slices to send: Send
Why are you using such a test in a Listener? That sounds to me like very non-object-oriented programming. You have probably got some poor design there. You can avoid problems with null Strings very easily, by swapping the order of operands, like this:That test cannot suffer a NullPointerException even if user is null.

There are a few instances where a formal null check is required: for example in the old-fashioned use of a FileReader. Note I am showing the correct way to do it with a finally block. Look at this post, and the post farther down where I realised I had made a mistake. That will show you how to check for nullity.
+Pie Number of slices to send: Send
Thanks to all for the response.
+Pie Number of slices to send: Send
You're welcome
Your mother is a hamster and your father smells of tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1986 times.
Similar Threads
tiles struts
how request.getParameter works?
~ operator
response.encodeURL
threads--yield
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:00:24.