Path extends ArrayList<K> { public Path<K> via(K... subKeys) { if (subKeys == null) { return this; } Path<K> newPath = new Path<K>(this); newPath.addAll(Arrays.asList(subKeys)); return newPath; } Path();  Path(List<K> keys);  Path(K... keys); @SuppressWarnings("unchecked") Path<K> to(K subKey); Path<K> via(K... subKeys); @Override String toString();  }
@Test @SuppressWarnings("unchecked") public void testVia() throws Exception { Path<Integer> p = new Path<Integer>(); assertEquals(p.via().size(), 0); assertEquals(p.via(1, 2, 3).size(), 3); assertEquals(p.via(1, 2, 3).toString(), "1/2/3"); }