<分区>
我有一个java函数。在第一个函数中,返回变量“ret”用第二个函数中的声明初始化,它在需要时在 try 内部初始化。大家觉得哪个更好呢?请以 List 为例,它可以是一个字符串和类型。谢谢
第一个函数:
public List<String> getNames() {
List<String> ret = new ArrayList<String>();
try {
// use ret
} catch(Exception e){
}
}
第二个函数:
public List<String> getNames() {
List<String> ret = null;
try {
// some more code
ret = new ArrayList<String>();
// use ret
} catch(Exception e){
}
}