gpt4 book ai didi

java - 安卓工作室说 'Local variable is redundant'

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:43:34 25 4
gpt4 key购买 nike

<分区>

我在许多方法上收到警告,说局部变量是多余的

这是一个示例方法:

public MyObject getMSListItem(int pos) {
MyObject li = getItem(pos);
return li;
}

现在看来,我想,我可以这样做来修复它:

public MyObject getMSListItem(int pos) {
return getItem(pos);
}

另一个例子:

public String getTeacher(int pos) {
ffTeacherListItem t = getItem(pos);
String teacher = t.teacher;
return teacher;
}

似乎这可能是:

public String getTeacher(int pos) {
ffTeacherListItem t = getItem(pos);
return t.teacher;
}

或者按照下面的建议,甚至更好!

public String getTeacher(int pos) {
return getItem(pos).teacher;
}

真的有这方面的“最佳实践”吗?一种方法比另一种更好吗?还是仅与代码可读性有关?

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