DoubleMapGenotype extends DoubleGenotype implements MapGenotype<K, Double> { @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public <G extends Genotype> G newInstance() { try { Constructor<? extends DoubleMapGenotype> cstr = this.getClass().getConstructor(List.class, Bounds.class); return (G) cstr.newInstance(keys, bounds); } catch (Exception e) { throw new RuntimeException(e); } } DoubleMapGenotype(List<K> keys, Bounds<Double> bounds); void init(Random random); @Override void init(Random random, int n); @Override boolean containsKey(K key); @Override Double getValue(K key); @Override void setValue(K key, Double value); @Override @SuppressWarnings({ "unchecked", "rawtypes" }) G newInstance(); @Override String toString(); @Override int getIndexOf(K key); @Override Collection<K> getKeys();  }
@Test public void testNewInstance() { List<MockObject> keys = new ArrayList<>(); MockObject m1 = new MockObject(1); MockObject m2 = new MockObject(2); keys.add(m1); keys.add(m2); DoubleMapGenotype<MockObject> doubleMapGeno = new DoubleMapGenotype<>(keys, new MockBounds()); doubleMapGeno.init(new Random()); DoubleMapGenotype<MockObject> other = doubleMapGeno.newInstance(); assertNotEquals(doubleMapGeno, other); assertTrue(other.isEmpty()); }