Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I make a constants class for my annotations?

Which is better?

  1. @SuppressWarnings("unchecked")
  2. @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.

like image 554
jacobko Avatar asked Dec 08 '25 12:12

jacobko


1 Answers

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.

like image 75
Jon Skeet Avatar answered Dec 11 '25 01:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!