Cod sursa(job #2518595)

Utilizator sratropSra Trop sratrop Data 6 ianuarie 2020 00:12:26
Problema Lowest Common Ancestor Scor 0
Compilator java Status done
Runda Arhiva educationala Marime 1.03 kb

import java.util.HashMap;

public class Main {
    static class BlockState {
        int blockValue;

        BlockState(int newValue) {
            blockValue = newValue;
        }

        @Override
        public boolean equals(Object o) {
            if(this == o) return true;
            if(o == null || getClass() != o.getClass()) return false;
            BlockState b = (BlockState) o;
            return (blockValue == b.blockValue);
        }

        @Override
        public int hashCode() {
            return blockValue;
        }
    }

    public static void main(String[] args) {
        HashMap<BlockState, Boolean> visited = new HashMap<>();
        BlockState b1 = new BlockState(1);
        visited.put(b1, true);
        BlockState b2 = new BlockState(1);
        if(visited.containsKey(b2)) {
            //you expect this to be executed
            System.out.println("It contains");
        } else {
            //but actually this will be executed ??!
            System.out.println("It does not contain");
        }
    }
}