Java隐藏特性
双花括号初始化语法(DoubleBraceInitialization)
1 | // 这里解释下这两个括号: |
注意:此特性可能存在的问题;
- gson 不能正确解析双花括号语法(【Java】那些踩过的坑 | 比特楼)
- 永远不要使用双花括号初始化实例,否则就会 OOM! - SegmentFault 思否
(匿名内部类,可能会导致 OOM) - Caused by: com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): com.lyloou.jetcache.UserServiceImpl$1
This is an anonymous class, which is not serializable by default in Kryo. Possible solutions: 1. Remove uses of anonymous classes, including double brace initialization, from the containing class. This is the safest solution, as anonymous classes don’t have predictable names for serialization.