The following statement causes a warning in Eclipse:
Map<String, String> options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
Warning:
Type safety: The expression of type Map needs unchecked conversion to conform to Map<String,String>
What is the best practice to handle this warning? Should I add an SupressWarning(“unchecked”) annotation? For the whole class? Or just the method? Or should I just ignore the warning? Or how can I get rid of this warning?
Until
DefaultCodeFormatterConstants.getEclipseDefaultSettingsis properly generified, I’d consider making a generified wrapper for it, and having the annotation on the internal local variable declaration inside of it. Also include a comment explaining why the annotation is “safe”.In general, you want the scope of a
SuppressWarningsannotation to be as small as possible, and you want to have as few of them as possible. You should also have a comment explaining your reasoning each time you use one.