Is there a tool for the conversion of duplicate literals into final Strings/magic numbers in Java?

72 views Asked by At

I have some Java files that use the same String values up to 20 times each, and I want a tool that replaces those Strings with a private static final String STRING_TO_CAPS_AS_CONSTANT or something along those lines. If it can also convert numbers into magic numbers, that would be great. I'm using Eclipse but if it's a standalone tool I can still make use of it.

1

There are 1 answers

2
AudioBubble On BEST ANSWER

I think Eclipse provides that already. If you select the whole String and press CTRL+1 it should give you the opportunity to choose: "Extract to constant". This will implicitly replace all occurrencies of your String with the new constant.