java.util.Objects.isNull vs object == null
Using java 8. seems Objects.isNull() is the recommended way, is there a way to get warning if we write like this "object == null" ?
Thanks !
java.util.Objects.isNull vs object == null
Using java 8. seems Objects.isNull() is the recommended way, is there a way to get warning if we write like this "object == null" ?
Thanks !
In the code sample as follows:
public static void main(String... args) {
List<String> list = Arrays.asList("a", "b", null, null);
boolean b = list.stream().anyMatch(str -> str == null);
System.out.println(b);
}
IntelliJ IDEA will suggest you a fix to change the lambda with method reference, and you will have:
boolean b = list.stream().anyMatch(Objects::isNull);
instead.
The inspection that is responsible for the fix is Java | Java language level migration aids | Java 8 | Lambda can be replaced with method reference.