本帖最后由 DOOR 于 2014-1-16 00:36 编辑
- class Person
- {
- String name;
- public Person(String name)
- {
- this.name = name;
-
- }
- }
- class Hello
- {
- public static void main(String[] args)
- {
- Person p1 = new Person("lisi");
- Person p2 = new Person("lisi");
- System.out.println(p1.equals(p2));
- String s1 = new String("zhangsan");
- String s2 = new String("zhangsan");
- System.out.println(s1.equals(s2));
- }
- }
复制代码 //打印结果一真一假,什么原因?
//equals不是比较对象内容的吗?
//p1和p2内容不一样?
|