1. 程式人生 > >物件 一個類的105303個物件之後 hashCode才會重複

物件 一個類的105303個物件之後 hashCode才會重複

static class KKKK {
      int a;
      int b;
   }

   public static void main(String[] args) {
      Map<Integer, Boolean> ccc = new HashMap<>();
      for (int i = 0; i < 1000000; i++) {
         KKKK bb = new KKKK();
//       System.err.println(bb.hashCode());
         if (ccc.containsKey(bb.hashCode())) {
            System.err.println("CCCCC::" + i);
            break;
         } else {
            ccc.put(bb.hashCode(), false);
         }
      }
   }

 

 

 

 

Connected to the target VM, address: '127.0.0.1:42682', transport: 'socket'
CCCCC::105303