Specific Collection type returned by Convenience Factory Method in Java 9 -
in java 9 have convenience factory methods create , instantiate immutable list, set , map.
however, unclear specific type of returned object.
for ex:
list list = list.of("item1", "item2", "item3");
in case type of list returned? arraylist or linkedlist or other type of list?
the api documentation mentions line, without explicitly mentioning linkedlist:
the order of elements in list same order of provided arguments, or of elements in provided array.
the class returned list.of
1 of package-private static classes , therefore not part of public api:
package java.util; ... class immutablecollections { ... static final class list0<e> extends abstractimmutablelist<e> { ... } static final class list1<e> extends abstractimmutablelist<e> { ... } static final class list2<e> extends abstractimmutablelist<e> { ... } static final class listn<e> extends abstractimmutablelist<e> { ... } }
so not arraylist (neither linkedlist). things need know is immutable , satisfies list
interface contract.
Comments
Post a Comment