Skip to content

Tag: annotations

Annotated setters that return class insance

For some time now I have been bothered by the lack of fluent interface setters. I am aware of Lomboks system however the generated functions still return a void. Would it be possible/and how to make a setter to return its class instance? Thanks Answer Answer solved with Accessors. Over any class which you&#82…

Make method accept only parameter with particular annotation

I have a method And I have a class which holds field And I have main class, where I call that method and pass him that: Problem is that the method accepts all the 3 parameters, (no warnings, errors, nothing) however only roomDao is annotated. Annotation itself: How to make the restriction, so that injectConfi…

How to conditionally serialize a field

I want to conditionally serialize a field. I figured out how to conditionally ignore a field with But what I really want to do is to redact the field. So if I have I get Field2 is correctly ignored. But what I really want is I have another annotation, @MaskSensitiveData So what I want to do is combine them. S…

Check if Annotation is inherited

I have an annotation and three classes like this: Is there any way I can determine if a present annotation is inherited or declared directly at the class? Something like a method public boolean isInherited(Class<?> clazz, MyAnnotation annotation) that should only be called if the annotation is present. …

What’s the difference between the two expressions?

and What’s the difference between them in java? It seems that the generated bytecode is identical. Answer It seems that the generated bytecode is identical. Then you got your answer. Semantically, the two constructs will result in the exact same behavior at runtime. So the only thing left: what does it …