SetUtil { @SuppressWarnings("unchecked") public static <T> Set<T> unmodifiableSet(T... types) { return Collections.unmodifiableSet( Stream.of(types).collect(toSet()) ); } private  SetUtil(); @SuppressWarnings("unchecked") static Set<T> unmodifiableSet(T... types);  }
@Test void unmodifiableSet() { final String[] words = {"A", "B", "C"}; final Set<String> set = SetUtil.unmodifiableSet(words); assertEquals(Stream.of(words).collect(toSet()), set); assertThrows(UnsupportedOperationException.class, set::clear); }