标签:
import java.util.ArrayList; import java.util.List; class Phone { private String brand; private double price; public Phone(String brand, double price) { this.brand = brand; this.price = price; } @Override public boolean equals(Object obj) { if(this == obj){ return true; } if(obj == null){ return false; } if(! (obj instanceof Phone)){ return false; } Phone phone = (Phone) obj; return this.brand.equals(phone.brand) && this.price==phone.price; } @Override public String toString() { return brand + price; } } public class Hello{ public static void main(String args[]) throws Exception{ List<Phone> list = new ArrayList<Phone>(); list.add(new Phone("红米",399)); list.add(new Phone("黑米",499)); System.out.println(list.get(1)); } }
标签:
原文地址:http://www.cnblogs.com/cyxxzjp/p/5811256.html