custom annotation naming
Custom annotations in Java should be named to describe what’s required of the method, and not which functionality we would like applied.
For example;
| |
Instead of;
| |
If we start naming our annotations after “how” they work, and not “what” we want, we go down a route of also describing the edge and error cases.
It’s very easy for a @CheckXYZ annotation to start accepting parameters that control; how the exception is thrown, which type of exception, etc.
There’s precedent for describing the requirements of the method, rather than “how” to implement the requirements, for example;
@NotNullinstead of@CheckNotNull@PostMappinginstead of@HandlePostRequest@ExceptionHandlerinstead of@HandleException
Name custom annotations based on their requirements, not their implementation.