示例:
class Item {
// 可重用的 public 零长度数组常量
public static final Item[] EMPTY_ARRAY = new Item[0];
}
class EmptyNode {
Item[] getChildren() {
// 不必要的零长度数组创建
return new Item[0];
}
}
在应用快速修复后:
class EmptyNode {
Item[] getChildren() {
return Item.EMPTY_ARRAY;
}
}