greencrest
greencrest

Reputation: 169

IntelliJ IDEA warns of "Unnecessary 'Arrays.asList' call"

final SomeObjectType[] list = webserviceResponse.getArrayOfObjects();
    if (list != null) {
        final List<SomeObjectType> responseList = Arrays.asList(list);
        for (final SomeObjectType prt : responseList) {
            // doing some factory conversion.
        }
    }

IntelliJ IDEA is giving me the warning

Unnecessary 'Arrays.asList' call

while I'm converting my array to a List. Why?

link to image

Can someone answer simply?

Upvotes: 2

Views: 1872

Answers (1)

vatbub
vatbub

Reputation: 3099

IntelliJ warns you about that because you could simply do

if (list != null) {
    for (final SomeObjectType prt : list) {
        // do something
    }
}

This works because arrays also have an iterator.

Upvotes: 2

Related Questions