简体   繁体   English

Java / Groovy通用类型推断

[英]Java / Groovy generic type inference

I'm writing Groovy (1.8.8) code running under JDK6 and it seems the following is legal: 我正在写在JDK6下运行的Groovy(1.8.8)代码,看来以下是合法的:

ConcurrentMap<Foo, Bar> statsRegistry = new ConcurrentHashMap<>()

Why is it permitted to omit the types on the right-hand side? 为什么允许省略右侧的类型? Is this a NEW Groovy feature or would this also be allowed in Java 6? 这是Groovy的新功能还是Java 6中也允许使用?

Groovy 1.8中引入了“ diamond operator”(类型推断),请参阅发行说明中的​​这一项目 ,并且Groovy 1.8在JDK6上可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM