How To Solve Potential Null Pointer Access The Variable XXX May Be Null At This Location

How To Solve Potential Null Pointer Access The Variable XXX May Be Null At This Location

How To Solve Potential Null Pointer Access The Variable XXX May Be Null At This Location

Intro

List < T > XXX = null;
沒有佔用記憶體空間,因此isEmpty() & size()不能使用。

List < T > XXX = new ArrayList();
有佔用記憶體空間,初始化是空集合,因此isEmpty() & size()可以用。