Id implements Serializable, Comparable<Id<T>>, Identity<T> { @SuppressWarnings("unchecked") public static <T> Id<T> createCached(long id) { return objectCache.getUnchecked(id); } protected  Id(long id); static Id<T> create(long id); @SuppressWarnings("unchecked") static Id<T> createCached(long id); @Override int hashCode(); @SuppressWarnings("rawtypes") @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(Id<T> o); final long id; }
@Test public void cachedIdReturnsTheSameInstance() { Assertions.assertSame(Id.createCached(RAW_ID), Id.createCached(RAW_ID)); }
@Test public void reachedMaxOfYourCache() { Id<Object> cached = Id.createCached(RAW_ID); LongStream.range(0, 6_000_000).forEach(Id::createCached); Assertions.assertNotSame(cached, Id.createCached(RAW_ID)); }