java - What does <> in Java mean?
问题描述
Looking at a library called mongojack 3.0 - https://github.com/mongojack/mongojack. This library contains a file called JacksonMongoCollection.java It has a method...
public JacksonCollectionKey<TResult> getCollectionKey() {
return new JacksonCollectionKey<>(getMongoCollection().getNamespace().getDatabaseName(), getMongoCollection().getNamespace().getCollectionName(), getValueClass());
}
This returns JacksonCollectionKey<>
This library compiles fine.
I have not seen an empty generic type definition before. How does this work?
解决方案
空的泛型类型括号用于编译器可以从上下文中推断出泛型类型。在您的情况下,编译器会将 TResult 插入空括号中。
推荐阅读
- python - .startswith 使用多个变量
- php - 数组一起作用于日期回显的 foreach 列表
- flutter - 切换选项卡时 AppBar 中不需要的空间
- sql-server - 尝试在 where 语句中选择记录(最大日期)
- flutter - 在文本字段中实现语音到文本的颤动
- pandas - numpy数组中允许的DataFrame
- sql - 在触发之前导致 ORA-04091
- python - 如何使用 pytest 为类范围的固定装置创建工厂?
- asp.net-core - 如何让 NSwag 识别 POST 路由上的“application/json”返回类型?
- python-3.x - 如何使用 Python GUI 关闭具有特定文件路径的外部程序