码迷,mamicode.com
首页 > 其他好文 > 详细

stream idea inspection warning

时间:2020-05-13 19:59:17      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:mapping   info   one   wing   cal   nts   class   which   temporary   

一、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

标签:mapping   info   one   wing   cal   nts   class   which   temporary   

原文地址:https://www.cnblogs.com/foolash/p/12884400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!