本文介绍了点运算符“。”(通用参数之前)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天看到这段代码:

  ImmutableMap< Class< ;?扩展ClientCommand>,CommandProcessorInterface> immutableMap = 
ImmutableMap。< Class< ;?扩展ClientCommand>,CommandProcessorInterface>(...

这个语法是什么意思?



ImmutableMap。< Class ..



我知道泛型是

有什么区别:



ImmutableMap< Class .. and ImmutableMap。< Class ..

解决它意味着你在 ImmutableMap 中调用一个通用静态方法,称为 类。



这与调用静态方法几乎相同,该方法嵌套在某个类中:

  SomeClass.staticMethod(); 

对于您的方法定义了类型参数的情况,您可以明确地提供泛型类型,并且这样做是这样的:

<$ p < Type> genericStaticMethod();

最后回答你的问题:

第一个通常用于创建泛型类的实例。它用于在类级别上定义泛型,而第二个用于调用嵌套在某个类中的泛型静态方法。


I saw this code today:

    ImmutableMap<Class<? extends ClientCommand>, CommandProcessorInterface> immutableMap =
            ImmutableMap.<Class<? extends  ClientCommand>, CommandProcessorInterface>of(...

What does this syntax mean?

ImmutableMap.<Class ..

I knew generics was right after the class name. No?

What is the difference between:

ImmutableMap<Class.. and ImmutableMap.<Class..

解决方案

It means you're invoking a generic static method, called of in the ImmutableMap class.

It's pretty much the same as you're invoking a static method, nested in some class:

SomeClass.staticMethod();

For the cases when your method has a type-parameter defined, you can explicitly provide the generic type and this is done like this:

SomeClass.<Type>genericStaticMethod();

And to answer you final question:

The first is usually used when creating an instance of a generic class. It's used to define the generic-type on class level, while the second is used to invoke a generic static method that's nested in some class.

这篇关于点运算符“。”(通用参数之前)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:40