import java.util.*;
class Counter {
}
class Groundhog2 {
    int ghNumber;
    Groundhog2(int n) { ghNumber = n; }
    public int hashCode() { return ghNumber; }
    public boolean equals(Object o) {
        return (o instanceof Groundhog2)
        && (ghNumber == ((Groundhog2)o).ghNumber);
    }   
}
public class SpringDetector2 {
    public static void main(String[] args) {
        Hashtable ht = new Hashtable();
        for(int i = 0; i < 10; i++)
        ht.put(new Groundhog2(i),new Counter());
        System.out.println("ht = " + ht + "\n");
        System.out.println(
            "Looking up prediction for groundhog #3:");
        Groundhog2 gh = new Groundhog2(3);
        if(ht.containsKey(gh))
        System.out.println((Counter)ht.get(gh));
    }   
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2021-06-30
  • 2022-12-23
  • 2021-05-29
  • 2021-09-21
  • 2021-10-05
  • 2022-12-23
  • 2021-07-17
相关资源
相似解决方案