java 创建匿名对象 类似于c# 中的 new { a:"aaa",b:"bbb"};
1 创建匿名对象
Object myobj = new Object() {
public final boolean success = true;
}
2 字面量方式初始化mapMap<String, String> myMap = new HashMap<>() {{
put("a", "b");
put("c", "d");
}};
}
3 初始化数组
var refEntityIDs = new ArrayList<String>(Arrays.asList(
BalanceConst.BEIDVoucherOptFail,
BalanceConst.BEIDAccountingDocument,
BalanceConst.BEIDAccDocOptPreTbl
));
参考
1 https://*.com/questions/8488833/what-is-the-java-equivalent-of-creating-an-anonymous-object-in-c
2 https://*.com/questions/6802483/how-to-directly-initialize-a-hashmap-in-a-literal-way