易截截图软件、单文件、免安装、纯绿色、仅160KB

java中重写equals方法

import java.util.Date;
class Dog{
 private String name;
 private Date birthday;
 
 
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Date getBirthday() {
  return birthday;
 }
 public void setBirthday(Date birthday) {
   this.birthday = birthday;
 }
 
 
}
public class Cat {
 /**Cat类中含有name和birthday两私有成员变量,且重写了equals方法和hashCode方法
  *
  * @param name 和 birthday
  *
  */
 
 private String name;
 private Date birthday;
 
 public Cat(){}
 
 
 
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Date getBirthday() {
  return birthday;
 }
 public void setBirthday(Date birthday) {
  this.birthday = birthday;
 }
 
 /*
  * 重写equals必须注意:
  *   1 自反性:对于任意的引用值x,x.equals(x)一定为true
  *   2  对称性:对于任意的引用值x 和 y,当x.equals(y)返回true,y.equals(x)也一定返回true
  *   3 传递性:对于任意的引用值x、y和z,如果x.equals(y)返回true,并且y.equals(z)也返回true,那么x.equals(z)也一定返   回 true
   * 4 一致性:对于任意的引用值x 和 y,如果用于equals比较的对象信息没有被修改,
   *           多次调用x.equals(y)要么一致地返回true,要么一致地返回false
   *   5 非空性:对于任意的非空引用值x,x.equals(null)一定返回false
   * 
   * 请注意:
   * 重写equals方法后最好重写hashCode方法,否则两个等价对象可能得到不同的hashCode,这在集合框架中使用可能产生严重后果
  */
 
 
 /*
  *  1.重写equals方法修饰符必须是public,因为是重写的O


相关文档:

JAVA实现的大整数加法

public class Test{ 
  public static String addBigNum(String str1,String str2){
     //找出两字符串的长短,方便后边引用;
     String longer = str1.length() > str2.length()? str1 : str2;
     String shorter = str1.length( ......

java正则表达式

   在使用RegularExpressionValidator验证控件时的验证功能及其验证表达式介绍如下:
只能输入数字:“^[0-9]*$”
只能输入n位的数字:“^d{n}$”
只能输入至少n位数字:“^d{n,}$”
只能输入m-n位的数字:“^d{m,n}$”
只能输入零和非零开头的数字:“^(0|[1- ......

JAVA加密算法

MD5算法是一种非常优秀的加密算法。
MD5加密算法特点:灵活性、不可恢复性。
       介绍MD5加密算法基本情况MD5的全称是Message-Digest Algorithm 5,在90年代初由MIT的计算机科学实验室和RSA Data Security Inc发明,经MD2、MD3和MD4发展而来。
Message-Digest泛指字节串(Message)的Has ......

Effective Java 学习笔记(2)

 有时,我们在写一个构造函数时,经常因为它包含众多的参数而苦恼,这时可以考虑用Builder模式来创建对象。
如,我们要设计一个营养成份的类,包含能量,蛋白质,脂肪,钙,铁,锌,维生素A, 维生素B1 ... 等,但在构造的时候,不一定每次都需要这些参数,如钙,铁,锌和维生素等是可选的,为了适应多种可能的搭配,比 ......

四个有用的Java过滤器

一、使浏览器不缓存页面的过滤器     
import javax.servlet.*;    
import javax.servlet.http.HttpServletResponse;    
import java.io.IOException;    
   
/**   
* 用于的使 Browser 不 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号