I currently have a requirement where I need to return null from 100s of methods if a given condition is false. I was thinking of using Java Annotations or Spring Aspects for thi
If I get you correctly, Spring @Conditional
annotation is what you want.
You create some public class that implements Spring's Condition
interface:
public class Test implements Condition {
...
}
Then you use the forementioned annotation with the parameter which takes as an argument that public class.
@Conditional(Test.class)
public Object someMethod(boolean context){
/*and so do some logics; if the value of 'context' variable is false, you can return
null; otherwise, just return like this*/
return new someMethodImpl1();
}
Hope I helped. And I'm glad of any kind of corrections. Cheers!