
errorprone.bugpattern.DeeplyNested.md Maven / Gradle / Ivy
The newest version!
Having an extremely long Java statement with many chained method calls can cause
compilation to fail with a `StackOverflowError` when the compiler tries to
recursively process it.
This is a common problem in generated code.
As an alternative to extremely long chained method calls, e.g. for builders,
consider something like the following for collections with hundreds or thousands
of entries:
```java
private static final ImmutableList FEATURES = createFeatures();
private static final ImmutableList createFeatures() {
ImmutableList.Builder builder = ImmutableList.builder();
builder.add("foo");
builder.add("bar");
...
return builder.build();
}
```
over code like this:
```java
private static final ImmutableList FEATURES =
ImmutableList.builder()
.add("foo")
.add("bar")
...
.build();
```
© 2015 - 2025 Weber Informatics LLC | Privacy Policy