Counterexample
##Positive example
When calling methods elsewhere, avoid unnecessary null pointersoptional null
//获取子目录列表 public List<CatalogueTreeNode> getChild(String pid) { if (V.isEmpty(pid)) { pid = BasicDic.TEMPORARY_DIRECTORY_ROOT; } CatalogueTreeNode node = treeNodeMap.get(pid); return Optional.ofNullable(node) .map(CatalogueTreeNode::getChild) .orElse(Collections.emptyList()); }
The above is the detailed content of Don’t return null in java development. For more information, please follow other related articles on the PHP Chinese website!