What does the dot operator `.` (before the generic parameter) mean?

前端 未结 3 1553
一个人的身影
一个人的身影 2020-12-06 05:30

I saw this code today:

    ImmutableMap, CommandProcessorInterface> immutableMap =
            ImmutableMap.

        
3条回答
  •  清歌不尽
    2020-12-06 06:28

    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.genericStaticMethod();
    

    And to answer you final question:

    What is the difference between ImmutableMap and ImmutableMap. ?

    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.

提交回复
热议问题