-2

I am starting with a utility projects which will give out of the box annotations to perform some tasks such as uppercasing, lowercasing, validating, performing some more trasnformation. As far I have seen that annotations are actually have no impact on code. So I want to know if there is a way that where I put the annotation on let say

@Casing(type="MyEnum.UpperCase")
private String name;

and while saving or retrieving the value it gives UpperCase String of the input.

Sagar Kharab
  • 369
  • 2
  • 18
  • You can surely do that. Where is the annotation processed? – ernest_k May 18 '18 at 11:31
  • Scan the classpath, find a class and fields to process, extract annotation parameters, change fields values according to these parameters. Yet you haven't shown any of these steps, so we can assume you made no attempt. – Andrew Tobilko May 18 '18 at 11:34

1 Answers1

1

In pure Java, You cannot do this. Annotations are passive elements in Java. Unfortunately, you can not write any code inside an annotation declaration.

But if you use some e.g Spring Stack you get a plenty way to do this e.g Aspect/AOP (exist in pure Java) performing a task on your annotation or you can create some Resolver Bean which makes this job behalf of you.