Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Additional Information Passing

Matthew Webster wrote:

There's even a neater way using annotations! Consider this:

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Exclude {
    String value() default "";
}

And use Annotation[][] Method.getParameterAnnotations() to detect annotations on the parameters of the invoked method.

Then you can write:

public class Test {

       public void secret (int i, @Excluded String userid) {

       }

public void secret (int i, @Excluded String userid, @Excluded String password) {

       }
...
}

Which is easier to write, and less fragile in case you add/remove/reorder arguments.

Rafal


Back to the top