Appreciate any help for creating custom annotation in JAVA by forcing Upper or Lower case for a pojo field. Like to get something like below
// CaseMode enum wou
Annotations are passive elements in Java; they can not have any behavior. As @maba said, you can not write any code inside an annotation declaration.
In order to have something similar to what you are trying to do, you need something which detects the annotation and performs some work. You have a few choices.
Writing a custom compile-time annotation processor allows you to preprocess the source code before compilation.
Aspect oriented programming can work both at compile and at run time. It's relatively easy to understand, needs however some tooling to be set up together with your project, depending where you deploy it.
Dynamic proxies are simple as well, but you need to change the way your code accesses the objects, probably by declaring some interfaces and using those instead of the classes, etc.
Code generation libraries fall on the complex side of the spectrum, giving lots of flexibility (they are for instance how Hibernate does its magic with your POJO objects).
Your statement // NEED HELP HERE
should be according to the following:
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Case {
CaseMode value();
}
If you think that you can have some code in there then you are wrong.