stream idea inspection warning

Posted foolash

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了stream idea inspection warning相关的知识,希望对你有一定的参考价值。

一、idea检查警告

Can be replaced with ‘peek‘ less... (Ctrl+F1) 
Inspection info: This inspection reports stream API call chains which can be simplified. It allows to avoid creating redundant temporary objects when traversing a collection.
The following call chains are replaced by this inspection:
    collection.stream().forEach() → collection.forEach()
    collection.stream().collect(toList/toSet/toCollection()) → new CollectionType<>(collection)
    collection.stream().toArray() → collection.toArray()
    Arrays.asList().stream() → Arrays.stream() or Stream.of()
    IntStream.range(0, array.length).mapToObj(idx -> array[idx]) → Arrays.stream(array)
    IntStream.range(0, list.size()).mapToObj(idx -> list.get(idx)) → list.stream()
    Collections.singleton().stream() → Stream.of()
    Collections.emptyList().stream() → Stream.empty()
    stream.filter().findFirst().isPresent() → stream.anyMatch()
    stream.collect(counting()) → stream.count()
    stream.collect(maxBy()) → stream.max()
    stream.collect(mapping()) → stream.map().collect()
    stream.collect(reducing()) → stream.reduce()
    stream.collect(summingInt()) → stream.mapToInt().sum()
    stream.mapToObj(x -> x) → stream.boxed()
    stream.map(x -> {...; return x;}) → stream.peek(x -> ...)
    !stream.anyMatch() → stream.noneMatch()
    !stream.anyMatch(x -> !(...)) → stream.allMatch()
    stream.map().anyMatch(Boolean::booleanValue) -> stream.anyMatch()
    IntStream.range(expr1, expr2).mapToObj(x -> array[x]) -> Arrays.stream(array, expr1, expr2)
    Collection.nCopies(count, ...) -> Stream.generate().limit(count)
    stream.sorted(comparator).findFirst() -> Stream.min(comparator)
Note that the replacements semantic may have minor difference in some cases. For example, Collections.synchronizedList(...).stream().forEach() is not synchronized while Collections.synchronizedList(...).forEach() is synchronized. Or collect(Collectors.maxBy()) would return an empty Optional if the resulting element is null while Stream.max() will throw NullPointerException in this case.

 

 

 

二、

 

 

...

 

以上是关于stream idea inspection warning的主要内容,如果未能解决你的问题,请参考以下文章

IDEA - Inspections

IDEA Inspections详解

idea pom引入依赖 Dependency ‘xxx‘ not found less... (Ctrl+F1) Inspect

IntelliJ IDEA 好用插件之analyze inspect code

IntelliJ IDEA 好用插件之analyze inspect code

Usage of API documented as @since 1.8+ less... (Ctrl+F1) Inspection info: This inspection finds all