首页 > 解决方案 > 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?

标签: javamongojack

解决方案


空的泛型类型括号用于编译器可以从上下文中推断出泛型类型。在您的情况下,编译器会将 TResult 插入空括号中。


推荐阅读