小编Col*_*ker的帖子

Java约定 - 命名局部变量与字段相同

编写一个程序来解释文本文件中的一行.
想知道我是否应该将方法'parseWordData'中的局部变量命名
scannedWord为oppposed word,因为word它已经是一个类字段.
只要我宣布一个新变量而不是重新分配旧变量,一切都应该没问题......对吗?

public class WordData {

private String word;
private int index;
private LinkedList<Integer> list;
private boolean pathFound;

public WordData(String word, int index, LinkedList<Integer> list, boolean pathFound) {
    this.word = word;
    this.index = index;
    this.list = list;
    this.pathFound = pathFound;
}

public WordData parseWordData(String line){
    Scanner scan = new Scanner(line);
    int index = scan.nextInt();
    String word = scan.next();
    //precond and subGoal
    LinkedList<Integer> list = new LinkedList<Integer>();
    while(scan.hasNextInt()){
        //add to LinkedList
    }
    return new …
Run Code Online (Sandbox Code Playgroud)

java naming-conventions local-variables

-1
推荐指数
1
解决办法
672
查看次数

标签 统计

java ×1

local-variables ×1

naming-conventions ×1