Page 1 of 1

Enhanced text request on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 334

Posted: Tue Mar 03, 2020 11:21 am
by javiut
Correctly states that all the artifacts List,Set,Map in Java 9 was added methods for creating unmodified collections for 0..10 parameters but it doesn't state that a handy varargs methods is also present when you need to create a collection with more than 10 parameters.

Code: Select all

    static <E> List<E> of(E... elements) {
        switch (elements.length) { // implicit null check of elements
            case 0:
                return ImmutableCollections.emptyList();
            case 1:
                return new ImmutableCollections.List12<>(elements[0]);
            case 2:
                return new ImmutableCollections.List12<>(elements[0], elements[1]);
            default:
                return new ImmutableCollections.ListN<>(elements);
        }
    }

It would be great if this var-args method is added.

Re: Enhanced text request on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 334

Posted: Tue Mar 03, 2020 10:09 pm
by admin
Noted. Thank you for your feedback!