### Question:
Maps { @SuppressWarnings("unchecked") public static <K, V> Map<K, V> build(Class<K> keyClas, Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("keysAndValues array must be even"); } Map<K, V> map = new HashMap<>(); K key = null; for (int i = 0; i < keysAndValues.length; i++) { if (i % 2 == 0) { key = keyClas.cast(keysAndValues[i]); } else { map.put(key, (V) keysAndValues[i]); } } return map; }  @SuppressWarnings("unchecked") static Map<K, V> build(Class<K> keyClas, Object... keysAndValues);  }### Answer:
@Test void simple_case() { Map<Integer, String> labelsByIndex = Maps.build(Integer.class, 1, "test1", 2, "test2"); assertThat(labelsByIndex).containsOnly(entry(1, "test1"), entry(2, "test2")); }
@Test void odd_number_of_key_and_values() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Maps.build(String.class, "key1")) .withMessage("keysAndValues array must be even"); }