Mincong Huang
Mincong Huang

Reputation: 5552

How to activate generic type warning in Eclipse?

I'm working with some Java code created in the previous version of JDK using the syntax:

List<String> myList = new ArrayList<String>();

But I wish to change them all to:

List<String> myList = new ArrayList<>();

I'm wondering if Eclipse can give me some warnings for this problem? I take a quick look at Java Compile Errors/Warnings Preferences, but I'm not sure which option to choose.

Upvotes: 0

Views: 151

Answers (2)

k5_
k5_

Reputation: 5558

For eclipse neon (i'm pretty sure it applies to earlier versions) there is a setting.

In the Preferences dialog

Java -> Compiler -> Errors/Warning.

In the section for "Generic Types" set the "Redundant type arguments" to something reasonable (i have it on warning)

Upvotes: 1

Christopher Schneider
Christopher Schneider

Reputation: 3915

Doesn't appear to be an option for that. Depending on the size of the project, have you considered using awk or grep to find all occurences?

This is something quick a dirty to print all occurences into the console. It uses ack. You can use sed to do a replacement, but, again, if it's a small number of occurrences, ack will show filenames and line numbers. ack "=\s*new .*<.+>\\(.*\\)"

Upvotes: 1

Related Questions