Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringBuilder with constant number of args can be replaced with concatenation #831

Closed
carterkozak opened this issue Sep 15, 2019 · 0 comments

Comments

@carterkozak
Copy link
Contributor

What happened?

StringBuilder usage with a constant number of arguments can be replaced with simple string concatenation (+ operator).

See the discussion on palantir/conjure-java#555

Compiling for a java 8 target results in the same bytecode, and applications which target java 9+ take advantage of JEP 280 for a more efficient codepath.

String value = new StringBuilder().append("foo").append(bar).toString();

Can be replaced with

String value = "foo" + bar;

What did you want to happen?

We can build an errorprone check with either a suggested fix, or a refaster rule to automatically replace these in existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant