google / google/error-prone

Suggested bug pattern: using "nested" method references

Open
#1,118 3 comments 0 reactions 0 assignees View on GitHub
Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

Using "nested" method references

(like `logger.trace("Created a new {}", getClass()::getName)`)

will result in unnecessary method calls because the `getClass` method would be called even if the getSimpleName reference was not consumed.

Above example should be replaced with `logger.trace("Created a new {}", () -> getClass().getName())`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.