Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 方法(字符串str)和方法(最终字符串str)之间的区别是什么_Java_Methods_Arguments_Keyword - Fatal编程技术网

Java 方法(字符串str)和方法(最终字符串str)之间的区别是什么

Java 方法(字符串str)和方法(最终字符串str)之间的区别是什么,java,methods,arguments,keyword,Java,Methods,Arguments,Keyword,在方法参数中使用Final关键字让我感到困惑 public void helloWorld(String str) { } public void helloWorld(Final String str) { } What is the differences between them? public void helloWorldfinal String str不允许在方法内部本地更改str的值,而如果没有final关键字,则可以在本地更改它 public void helloWo

在方法参数中使用Final关键字让我感到困惑

public void helloWorld(String str)
{

}


public void helloWorld(Final String str)
{

}

What is the differences between them?
public void helloWorldfinal String str不允许在方法内部本地更改str的值,而如果没有final关键字,则可以在本地更改它

public void helloWorld(String str)
{
     str = "something"; // OK
}


public void helloWorld(final String str)
{
    str = "something"; // ERROR
}

当然,即使是helloWorldString str也不能更改传递给该方法的字符串的值,因为Java是一种按值传递语言。

还有int或任何其他数据类型。@相信int和任何其他数据类型的答案都是一样的。