see*_*ess 8 android warnings lint android-studio
Variable is already assigned to this value
执行以下操作时,我收到 lint 警告
String[] sa =getStringArray();
sa = modifyArrayandMakeAwesomer(sa); //get the warning here
Run Code Online (Sandbox Code Playgroud)
对我来说似乎是一个新的警告。也许我的 lint 设置已更改。该代码按预期工作,没有任何错误。这是不好的做法吗?我应该声明第二个字符串数组吗?
小智 5
因为modifyArrayandMakeAwesomer(sa)正在使用其引用修改您的数据,
class Person {
String name;
}
// this method just return the string value after making it uppercase,
public static Person modifyReference(Person p)
{
p.name = "Gaurav";
return p; // we don't need to return this from here since we are modifying directly to the reference.
}
public static int main(String[] args)
{
Person p = new Person();
p.name = "Max";
System.out.println(p.name);
modifyReference(p); // this is what you should do,
p = modifyReference(p); // this is useless, since you have passed the reference of Person class
System.out.println(p.name);
}
Run Code Online (Sandbox Code Playgroud)
小智 -6
那么您的代码可能会令人困惑。这就是您收到此警告的原因。
您可以在“文件 | 设置 | 编辑器 | 检查 | Java - 声明冗余”中禁用“变量分配给自身”检查。
| 归档时间: |
|
| 查看次数: |
2413 次 |
| 最近记录: |