简体   繁体   中英

Take method argument as an argument in the annotation in Java 8

I have looked up and till now it doesn't seem possible, so, if that's the case, what is the best alternative to meet the following requirement?

@Authentication_Annotation(id, password)
public void method(String id, String password, String param) {
    // Does something if ID and Password are correct.
}

Coming from a python background, this would have been possible using decorators. Can we still do it in java, without calling a method that authenticates every time a method needs to be provided authentication?

You can access method args directly in your annotation instead of passing it as arguments explicitly.

Using AOP: Get method arguments using Spring AOP?

Anyways there seems to be another way via reflection using DynamicProxy: Java method missing (ala Ruby) for decorating?

It is impossible in Java (at least without ungodly amount of very dark black magic).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM