Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

class Wurst {
    public String name;
    public int count;

    public boolean equals(Wurst w) {
        return true;
        // return w.hashCode() == this.hashCode();

    }

    public int hashCode() {
        // System.out.println(this.name + " " + this.count + " " + Objects.hash(this.name, this.count));
        return 1;
        // return Objects.hash(this.name, new Integer(count));
    }
}

public class Main {
    public static void main(String[] args) {
        Wurst w1 = new Wurst();
        w1.name = "Peng";
        w1.count = 2;

        Wurst w2 = new Wurst();
        w2.name = "Peng";
        w2.count = 2;

        Map<Wurst, Integer> m = new HashMap<Wurst, Integer>();
        m.put(w1, 1);
        System.out.println(w1.equals(w2) + " " + m.containsKey(w1) + " " + m.containsKey(w2) + " " + m.size());
        m.put(w2, 2);

        System.out.println("Size " + m.size());

        System.out.println("WTF " + w1.hashCode() + " " + w2.hashCode() + " " + w1.equals(w2));

        for (Map.Entry<Wurst, Integer> entry : m.entrySet()) {
            System.out.println(entry.getKey().name + "/" + entry.getValue());
        }
    }
}