Linked Questions

17 votes
2 answers
22k views

What's the best way to do null-safe contains on a Java collection? in other words - if (collection != null && collection.contains(x)) ? I was hoping Apache commons-collections had ...
wrschneider's user avatar
1 vote
6 answers
5k views

I have a doubt regarding coding standard of a null check. I want to know the difference between if(a!=null) and if(null!=a) which one is better,which one to use and why?
Abx's user avatar
  • 2,872
7 votes
4 answers
11k views

Supposed I have a List<SomeObject> and have a function that return the reference of that object if available. SomeObject GetSomeObject(List<SomeObject>, int x){ /* Search for object ...
jamesalone's user avatar
9 votes
3 answers
24k views

It seems widely accepted that assert statements should be reserved for testing and disabled in production because errors should have been resolved by then, and enabling assertions affects performance. ...
ACHC's user avatar
  • 342
8 votes
4 answers
14k views

I have seen code where almost every variable in all application layers is checked for not being null. I have also seen code almost without this. if(object != null){} What are the best practices for ...
user avatar
8 votes
2 answers
17k views

I want to compile simple code with oracle jdk 1.8: class Foo { public static void test(@NotNull String a) {} } But idea not understand such code, and suggest to add: import com.sun.istack....
user1244932's user avatar
  • 8,282
2 votes
7 answers
2k views

Suppose I have a function that takes three parameters. Of course I could check that any two parameters of this function is null in this way. returnType function(p1, p2, p3){ if((p1 == null &&...
QuestionEverything's user avatar
8 votes
3 answers
3k views

I don't feel satisfied by avoiding null in OOP. Is there any alternative solution? I don't like to avoid it in this way either. What is the best possible way to handle it?
Madhav Bhattarai's user avatar
5 votes
4 answers
5k views

I was going through this post related to handling of nulls. One of the recommendation (as per the SO post) is to use Assert when nulls are not valid. I have (so far) used nulls extensively in Test ...
Tilak's user avatar
  • 30.8k
0 votes
6 answers
7k views

Is this bad practice or any performance hit, this is to check x is not equal to null if( !(x == null) ){ System.out.println("x is not a null value"); }
someone's user avatar
  • 6,572
1 vote
5 answers
1k views

Suppose I have 10 lines of code. Any line maybe throw a NullPointerException. I don't want to care about these exceptions. If a line throws the exceptions, I want the executor jump to next line and go ...
Nguyen Minh Binh's user avatar
4 votes
3 answers
601 views

I have read this topic: Avoiding != null statements but I don't see benefits. If you return empty array, you need to examine where the "real" array is, and where the empty array is. Instead of using ...
Avershin Dmitry's user avatar
1 vote
5 answers
7k views

I am working in Ruby and have found the need to have conditional return statements at the end of some/most of my methods. Here is what I have: # <ident-list> -> [ident] <ident-A> ...
Hunter McMillen's user avatar
66 votes
1 answer
4k views

I have an app uploaded on PlayStore and getting crash on it java.lang.NullPointerException from android.app.ActivityThread.updateLocaleListFromAppContext I have tried searching a lot online to check ...
Richie's user avatar
  • 693
4 votes
2 answers
7k views

I don't find the appropriate solution for my question. As far as I know returning null is a not a good way to write clean code, as the book Clean Code says. However there are many different opinions ...
Alex Blasco's user avatar

15 30 50 per page
1
3 4
5
6 7
12