java equals
2015-12-29 00:11
369 查看
java equals 的用法
class animal { int color; int height, weight; public animal(int color, int height, int weight) { this.color = color; this.height = height; this.weight = weight; } public boolean equals(Object obj) { if (obj == null) { return false; }else { if (obj instanceof animal) { animal c = (animal)obj; if (c.color == this.color && c.height == this.height && c.weight == this.weight) { return true; } } } return false; } } // equals 重写 public class TestEquals { public static void main(String[] args) { animal a1 = new animal(1,2,3); animal a2 = new animal(1,2,3); System.out.println(a1 == a2); System.out.println(a1.equals(a2)); } }
相关文章推荐
- java开发中如何使用JVisualVM进行性能分析
- spring boot自动配置幕后
- Spring教程
- lightweight java profiler与java flame graph初了解
- java数据类型
- java关键字
- Java 数组基础
- java按日期加1
- java比较日期
- java基础之反射
- java基础之注解
- 如何利用JConsole观察分析Java程序的运行并进行排错调优
- 2015年12月28日 Java基础系列(六)流
- java基础笔记--Map
- java的NIO概述
- XSS跨站脚本攻击(三)-- 结合Spring MVC框架
- Android Studio中导入Eclipse项目
- 给jdk写注释系列之jdk1.6容器(8)-TreeSet&NavigableMap&NavigableSet源码解析
- javase实现购物车功能
- Jsp学习笔记:javaBean属性命名规范