package com.super2; public class IPhone { public String name; public double cpu; public double screen; public double member; public void camera() { System.out.println("拍照美美哒"); } } package com.super2; public class Oppo extends IPhone{ // public String name = "Oppo"; public double cpu; public double screen; public double member; public Oppo() { // TODO Auto-generated constructor stub System.out.println("Oppo类执行了!!!"); } public void Advertisment() { System.out.println("前后两千万柔光双摄,照亮你的美"); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Oppo other = (Oppo) obj; if (Double.doubleToLongBits(cpu) != Double.doubleToLongBits(other.cpu)) return false; if (Double.doubleToLongBits(member) != Double.doubleToLongBits(other.member)) return false; if (Double.doubleToLongBits(screen) != Double.doubleToLongBits(other.screen)) return false; return true; } } package com.super2; public class Initial { public static void main(String[] args) { // TODO Auto-generated method stub Oppo oppoR9 = new Oppo(); Oppo oppoR11 = new Oppo(); oppoR9.cpu = 2.0; oppoR11.cpu= 2.0; oppoR9.screen = 5.5; oppoR11.screen= 5.5; oppoR9.member = 1024; oppoR11.member = 1024; oppoR9.Advertisment(); // System.out.println(oppoR9); // System.out.println(oppoR11); if (oppoR9.equals(oppoR11)) { System.out.println("两个对象一样"); }else { System.out.println("俩对象不一样"); } } }
自己写了个equals比较
这有什么问题吗?