java equals 方法
阿新 • • 發佈:2017-06-23
pack void print ava cnblogs nbsp system 方法 ring
package com.mydemo.controller; public class TestEquals { public static void main(String[] args) { Dog d1 = new Dog(1, 2, 3); Dog d2 = new Dog(1, 2, 3); // d1 永遠不等於 d2,比較的是兩個對象的引用 System.out.println(d1 == d2); // Object 的equals 方法默認比較兩個對象的引用 System.out.println(d1.equals(d2));// String 類重寫了Object 的equals方法 } } class Dog { int color; int weight; int height; public Dog(int color, int weight, int height) { this.color = color; this.weight = weight; this.height = height; } }
java equals 方法