我是靠谱客的博主 魁梧水杯,这篇文章主要介绍double java 初始化,什么是Java中的Double Brace初始化?,现在分享给大家,希望可以做个参考。

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(99)

评论列表共有 0 条评论

立即
投稿
返回
顶部