filmov
tv
Java Clean Code Tutorial #5 - Comparing String Constants
Показать описание
Java String constant comparison is one of the most popular and heavily used java statements. I feel it’s very important that all developers are aware of this one simple tip when performing comparisons to avoid unexpected Null Pointer Exceptions.
In order to avoid null pointer exceptions, always place the constant first during the comparison.
For example, the graceful validation below will not throw a null pointer is the variable is null. The risk prone code will throw a null pointer exception if the variable is null.
Graceful validation - CONSTANT.equals(variable)
I feel it is important developers know about this idiom and when to apply it. It can drastically improves codebases with such small changes, unless you want the code to blow up! But usually i don't.
Share this quick tip with your team & fiends.
Software is written once and read hundreds of times. So let’s make our fellow developers life easier.
Why clean code?
Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers.
Don’t forget to subscribe for your regular dose of Java Tutorials!
STOP THE ROT.
Till episode 6,
Philip
Episode 5 of the free Java Clean Code Training Series.
In order to avoid null pointer exceptions, always place the constant first during the comparison.
For example, the graceful validation below will not throw a null pointer is the variable is null. The risk prone code will throw a null pointer exception if the variable is null.
Graceful validation - CONSTANT.equals(variable)
I feel it is important developers know about this idiom and when to apply it. It can drastically improves codebases with such small changes, unless you want the code to blow up! But usually i don't.
Share this quick tip with your team & fiends.
Software is written once and read hundreds of times. So let’s make our fellow developers life easier.
Why clean code?
Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers.
Don’t forget to subscribe for your regular dose of Java Tutorials!
STOP THE ROT.
Till episode 6,
Philip
Episode 5 of the free Java Clean Code Training Series.
Комментарии