易截截图软件、单文件、免安装、纯绿色、仅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程序实现解压缩文件

package com.huawei.globe;
import java.util.zip.*;
import java.io.*;
public class Compress {
 public Compress() {
 }
 // 压缩目录下的文件
 public void compress(String zipFileName, String inputFile) throws Exception {
  compress(zipFileName, new File(inputFile)); ......

【转】给Java包取一个独一无二的名字

来源:http://bbs.hackline.net/thread-3620-1-1.html
隐藏具体实现是Java语言的主要特点之一。正是因为这个原因,所以Java语言的移植性就特别好。如有个程序员编写了一个实现随机数的程序库,那么其他
程序开发人员只需要知道这个程序库需要传入那些参数,就可以使用这个类。现在无论是网上还是平时的工作中,有很多现成 ......

Java Type VS Hibernate Type

Java Class Attribute Type         Hibernate Type               Possible SQL Type-Vendor Specific
Integer, int, long short &n ......

Java正则验证

import java.util.regex.*;

public final class RegExpValidator
{
/**
* 验证邮箱
* @param 待验证的字符串
* @return 如果是符合的字符串,返回 <b>true </b>,否则为 <b>false </b>
*/
public static boolean isEmail(String str)
{ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号