Which is better?
@SuppressWarnings('unchecked')@SuppressWarnings(AnnotationConstants.UNCHECKED)
Where AnnotationConstants is a typical constants class…
public final class AnnotationConstants { private AnnotationConstants() { } public static final String UNCHECKED = 'unchecked'; ... }
I know that there are a lot of general arguments for and against constants classes–and that’s exactly what I’m not interested in. I want to know if a constants class specifically for annotations is a good idea or a bad idea.
For this specific example I’d stick with literals. After all, you’re trying to suppress warnings – if you use the wrong literal, the warning won’t be suppressed, which will draw your attention to the problem.