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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -