Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
90 views
in Technique[技术] by (71.8m points)

java - Warn the developer while changing the param name

I am having a requirement where I need to fetch a param the value and validate before a method is invoked. I use MethodInterceptor (org.aopalliance.intercept.MethodInvocation) for this.

My method has three String parameters. I need to validate only the second parameter or specifically the parameter with the name pname. Currently, I use the following logic to validate the value of this parameter. But I have to hard code the param name or hardcode the index.

    int i=0;
    for(Parameter param: invocation.getMethod().getParameters()) {
     
        if(param.getName().equalsIgnoreCase("pname")) {
            //do validation using invocation.getArguments()[i]
        }
     i++;
    }

Either approach will fail if somebody modifies the method. Do we have a better approach or in worst case warn the future developer while he modifies the method param.

question from:https://stackoverflow.com/questions/65662078/warn-the-developer-while-changing-the-param-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...