Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions references/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ List<String> copy =
### Why modern wins
- **Smart copy:** Skips the copy if the source is already immutable.
- **One call:** No manual ArrayList construction + wrapping.
- **Defensive copy:** Changes to the original don't affect the copy.
- **Any Collection:** Accepts any Collection as input—no intermediate ArrayList conversion needed.

### References
- [List.copyOf()](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/List.html#copyOf(java.util.Collection))
Expand Down Expand Up @@ -262,17 +262,20 @@ var reversed = list.reversed();

## Typed stream toArray
- **Since:** Java 8
- **Old approach:** Manual Array Copy (Pre-Streams)
- **Old approach:** Manual Filter + Copy (Pre-Streams)
- **Modern approach:** toArray(generator) (Java 8+)
- **Summary:** Convert streams to typed arrays with a method reference.
- **Summary:** Filter a collection and collect the results to a typed array using a single stream expression.

### Before
```java
List<String> list = getNames();
String[] arr = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
arr[i] = list.get(i);
List<String> filtered = new ArrayList<>();
for (String n : list) {
if (n.length() > 3) {
filtered.add(n);
}
}
String[] arr = filtered.toArray(new String[0]);
```

### After
Expand All @@ -285,7 +288,7 @@ String[] arr = getNames().stream()
### Why modern wins
- **Type-safe:** No Object[] cast — the array type is correct.
- **Chainable:** Works at the end of any stream pipeline.
- **Concise:** One expression replaces the manual loop.
- **Concise:** No intermediate list — one expression replaces the manual loop and copy.

### References
- [Stream.toArray()](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/Stream.html#toArray(java.util.function.IntFunction))
Expand Down
2 changes: 1 addition & 1 deletion references/detection-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _Auto-generated from upstream YAML data. Do not edit manually._
- **map-entry-factory** (Java 9+): Old=`SimpleEntry` | Detect: `SimpleEntry`
- **reverse-list-iteration** (Java 21+): Old=`Manual ListIterator` | Detect: `System.out.println(`, `list.listIterator(list.size())`, `it.hasPrevious()`, `it.previous()`, `out.println(element)`
- **sequenced-collections** (Java 21+): Old=`Index Arithmetic` | Detect: `list.get(list.size() - 1)`, `list.get(0)`
- **stream-toarray-typed** (Java 8+): Old=`Manual Array Copy` | Detect: `list.size()`, `list.get(i)`
- **stream-toarray-typed** (Java 8+): Old=`Manual Filter + Copy` | Detect: `new ArrayList(`, `n.length()`, `filtered.add(n)`
- **unmodifiable-collectors** (Java 16+): Old=`collectingAndThen` | Detect: `Collectors.collectingAndThen(`, `Collectors.toList(`

## Concurrency
Expand Down
3 changes: 2 additions & 1 deletion references/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ class Square extends Shape {

### Before
```java
if (shape instanceof Circle c) {
if (shape instanceof Circle) {
Circle c = (Circle) shape;
if (c.radius() > 10) {
return "large circle";
} else {
Expand Down