java方法使用final修饰参数的作用

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;
    }

}

报错如下:

image-20210925141026888

总结

final修饰的方法参数,在方法体里面不能被修改

(img-OsOItSVE-1632550799013)]

总结

final修饰的方法参数,在方法体里面不能被修改

static不能修饰方法参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值