This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Hints > General > Use Functional Operations should be "Warning on Current Line" by default | ||
---|---|---|---|
Product: | java | Reporter: | brettryan <brettryan> |
Component: | Hints | Assignee: | Svata Dedic <sdedic> |
Status: | NEW --- | ||
Severity: | normal | CC: | terje7601 |
Priority: | P4 | ||
Version: | 8.0 | ||
Hardware: | PC | ||
OS: | Mac OS X | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
brettryan
2014-01-28 06:09:30 UTC
Actually, it should look like: Set<String> ids = getAllWidgets().stream().map(Widget::getId).collect(toSet()); which is at least as small & clear as the original. Very true, though as toSet() returns Set<T> it's not clear it's returning a HashSet (which it does), though its implementation could change. It could be said to be more explicit with: Set<String> ids = getAllWidgets().stream().map(Widget::getId).collect(toCollection(HashSet::new)); The IDE could generate this form more generically as it could always identify the supplier collection. Ah yes, I see your point now. If automatic conversion is provided (which in my opinion isn't the best solution, cf. issue 247772), it's definitely safer to do as you suggest, since toSet() & toList() provide no guarantees whatsoever (not even mutability, as I wrongly assumed). Netbeans suggest that I edit the following: for (Double value : values) { sum += value; } To: sum = values.stream().map((value) -> value).reduce(sum, (accumulator, _item) -> accumulator + _item); Which is just plain obfuscating (In reply to gromit190 from comment #4) > Netbeans suggest that I edit the following: > > for (Double value : values) { > sum += value; > } > > > To: > > sum = values.stream().map((value) -> value).reduce(sum, (accumulator, > _item) -> accumulator + _item); > > > Which is just plain obfuscating I would say it'/ more of a lack of understanding the stream API, however, a simpler form would be double sum = values.stream().reduce(0.0, Double::sum); You can use a mapToDouble but the result requires an additional step. double sum = values.mapToDouble(Double::doubleValue).sum(); Hints could then be enhanced to use one of the above for number types. Note that Arrays.stream has overloads for primitive arrays which return a number based stream avoiding the need for the mapTo_ |