上代码
String ss = null;
// false
System.out.println(ss == "");
// 报错 java.lang.NullPointerException
// System.out.println(ss.equals(""));
// false
System.out.println(Objects.equals(ss,""));
Long id = null;
System.out.println(id);
// 报错
System.out.println(id == 0);
// false
System.out.println(Objects.equals(id,0));
// true
System.out.println(Objects.equals(id,null));
总结
以后是不是用到比较的时候,都需要用objects.equals??
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。