IntelliJ IDEA tell Unnecessary 'Arrays.asList' call
IntelliJ IDEA tell 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.
}
}
Getting tip that Unnecessary 'Arrays.asList' call while converting array to list, why?
link to image
Can someone simply answer?
list
If IntelliJ means
responseList = Collections.singletonList(list);
then the compile time class is not an array but some Object. Michel_T has a point.– Joop Eggen
Jun 29 at 10:27
responseList = Collections.singletonList(list);
Can you share the full snippet?
– Mureinik
Jun 29 at 11:52
sorry, added explanation to 'list'
– greencrest
Jun 29 at 11:56
1 Answer
1
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.
thanks, completely understand
– greencrest
Jun 29 at 11:57
Consider marking the asnwer as the solution if it solved your problem, thanks :)
– vatbub
Jun 29 at 11:58
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
what's
list
?– Michel_T.
Jun 29 at 10:22