概述
What is Double Brace initialization syntax ({{ ... }}) in Java?
解决方案
Double brace initialisation creates an anonymous class derived from the specified class (the outer braces), and provides an initialiser block within that class (the inner braces). e.g.
new ArrayList() {{
add(1);
add(2);
}};
Note that an effect of using this double brace initialisation is that you're creating anonymous inner classes. The created class has an implicit this pointer to the surrounding outer class. Whilst not normally a problem, it can cause grief in some circumstances e.g. when serialising or garbage collecting, and it's worth being aware of this.
最后
以上就是魁梧水杯为你收集整理的double java 初始化,什么是Java中的Double Brace初始化?的全部内容,希望文章能够帮你解决double java 初始化,什么是Java中的Double Brace初始化?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复