for java beginner 13 java反射配列の反射(上)実はArrayList HashSet HashCode
JAva反射配列の反射(上)は実はArrayList HashSet HashCode
ArrayList HashSet HashCode
--------------------
--------------------------------
-------------------------------テストについて、次の記事にしましょう
ArrayList HashSet HashCode
--------------------
package com.ncs;
public class Point {
private int x;
public int y;
public String s1 ="ball";
public String s2="hubin";
public String s3="zhangxiaoxiang";
// , public
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Point other = (Point) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
}
--------------------------------
package com.ncs;
import java.util.Collection;
import java.util.HashSet;
public class ReflectInCollection {
public static void main(String[] args) {
//Collection collection = new ArrayList();
Collection collection = new HashSet();
Point p1 = new Point(3,3);
Point p2 = new Point(5,5);
Point p3 = new Point(3,3); // p1
collection.add(p1);
collection.add(p2);
collection.add(p3);
collection.add(p1);
System.out.println(collection.size()); //4
// ArrayList() HashSet() //3
//ArrayList , ,
//★ , ,[ ]
// ArrayList ,
//HashSet() , , ★
// ,p1 p3 , , eques
//★ eques hashcode ,hashcode
// Point equals hashcode
//IDE ,
// ,
// HashSet() 2 p1 == p3
// public int hashCode() , 3
// HashSet() hashCode()
//hash ,
// ,
// ??? ???? ??
// , ??
// , ,
// Hash ,
// HASH
//
// , object ,
// HASH ,★[ ArrayList ]
// ,
// , , equals,
// , equals, ,JVM ,
// hashset , ,
// !
//
// equals ,
//hashcode
// , equals , hashcode
// , hash , hashcode
//
// ,
// hashCode() ,
//hashCode() , hashcode()
// ,IDE
// , equals , hashcode
// ,"BB" "Aa" equals ,
//hashcode()
//★★ , hash ,
// , contains , ..
}
}
-------------------------------テストについて、次の記事にしましょう