81 ms·
Another example is Java's java.util.Map.of. It's a convenient method to construct a map in a single statement. https://docs.oracle.com/en/java/javase/11/docs/a
by sevenproxies 5y ago
Another example is Java's java.util.Map.of. It's a convenient method to construct a map in a single statement.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Map.html#of(K,V,K,V,K,V,K,V,K,V,K,V,K,V,K,V,K,V,K,V) https://docs.oracle.com/en/java/javase/11/docs/api/java.base...
- laurensr 5y agoDo note that the created map is immutable. However, you could pass the created map to the constructor HashMap (or another type) to obtain a mutable copy of the Map created using Map.of
- mileza 5y agoThis kind of function overload is present everywhere in the Java collection framework (and probably other libraries). It is a performance optimization (variadic arguments in Java require creating an array), and variadiac overloads also exist (Map.of needs a list of Map.Entry for type safety) for creating collections of any size. https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#of(E,E,E,E,E,E,E,E,E,E) https://docs.oracle.com/en/java/javase/11/docs/api/java.base...