java方法使用final修饰参数的作用
参考网址:
https://blog.csdn.net/qing_mei_xiu/article/details/79557767?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163184453616780366581551%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163184453616780366581551&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-1-79557767.first_rank_v2_pc_rank_v29&utm_term=java+%E6%96%B9%E6%B3%95%E5%8F%82%E6%95%B0%E4%BD%BF%E7%94%A8final%E4%BF%AE%E9%A5%B0%E4%BD%9C%E7%94%A8&spm=1018.2226.3001.4187
情景在线
@ApiOperation("用户列表")
@GetMapping(value = "/user/userList")
@Authentication(accountTypes = { "1" })
public AjaxResponse userList(@RequestParam(required = false, name = "account") String account,
@RequestParam(defaultValue = "1") final int index, @RequestParam(defaultValue = "10") final int size) {
return ajax(response -> {
UserCondition userCondition = new UserCondition();
userCondition.setAccount(account);
userCondition.setIndex(index);
userCondition.setSize(size);
response.addData("userList", userApplication.pageByCondition(userCondition));
}, throwable -> AjaxResponse.failure(500, "查询用户列表出错!").addData(ERRORS, throwable.getMessage()));
}
示例代码
import java.io.IOException;
public class MyTest {
public static void main(String[] args) throws IOException {
String data1 = getData1(1, 1);
System.out.println(data1);
String data2 = getData2(2, 2);
System.out.println(data2);
}
private static String getData1(final int param1 , final int param2){
param1 = 1;
return ""+param1+param2;
}
private static String getData2(final Integer param1 , final Integer param2){
param1 = 1;
return ""+param1+param2;
}
private String getData3(Integer param1,Integer param2){
param1 = 1;
return ""+param1+param2;
}
private String getData4(static Integer param1,static Integer param2){
param1 = 1;
return ""+param1+param2;
}
}
报错如下:
总结
final修饰的方法参数,在方法体里面不能被修改
(img-OsOItSVE-1632550799013)]
总结
final修饰的方法参数,在方法体里面不能被修改
static不能修饰方法参数