gpt4 book ai didi

android - Lint 警告 : Variable is already assigned to this value

转载 作者:搜寻专家 更新时间:2023-11-01 09:21:59 27 4
gpt4 key购买 nike

我收到 lint 警告变量已经分配给这个值当做类似下面的事情时

String[] sa =getStringArray();
sa = modifyArrayandMakeAwesomer(sa); //get the warning here

对我来说似乎是一个新的警告。也许我的 lint 设置已更改。该代码按预期工作,没有任何错误。这是不好的做法吗?我应该声明第二个字符串数组吗?

最佳答案

因为 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);
}

关于android - Lint 警告 : Variable is already assigned to this value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295495/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com