Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lint warning about string comparison in android java

Tags:

java

android

I know in java we are supposed to use String.equals to compare the value of two string objects. However, I've been a C++ programmer for too long to remember that we can't use "==" to compare two strings. I keep making the same mistakes again, again and again.

I guess we couldn't overload an operator like the way we do in C++. I am developing android apps in eclipse. Is there anyway to create a lint rule to at least throw a warning when I attempt to use "==" to compare two Strings?

like image 981
Stephen Cheng Avatar asked Jan 23 '26 19:01

Stephen Cheng


1 Answers

If you are using Android Studio, open the Preferences dialog, select Inspections, and search for "==". You will see a number of "Probable bugs" that you can checkmark. By the way, the option for Object comparisons does not cover Number or String comparisons.

enter image description here

like image 83
cybersam Avatar answered Jan 26 '26 10:01

cybersam