且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有 NullPointerException 的情况下返回数组对象?

更新时间:2022-03-19 21:28:44

行(1)

Man[] man = new Man[1];

隐藏在这行(2)中声明的实例变量

is hiding the instance variable declared in this line (2)

private Man[] man;

任何体面的 IDE 都会对此显示警告.

any decent IDE would show a warning for this.

这里是你应该如何初始化第 (1) 行中用第 (2) 行声明的数组 man

here is how you should initialize the array man in the line (1) declared with line (2)

man = new Man[1];