Invoking statically imported method with explicit type parameters

后端 未结 5 1898
梦毁少年i
梦毁少年i 2021-01-03 20:03

This is the follow up of my question here: Weird Java generic.

If I have a code like this:

Casts. cast(iterable[index]);
<
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 20:16

    I'm pretty sure the answer is no--if you want to use a generic method call, you need an object to call it on (foo.doSomething()). If the method is static, you need the class ( Foo.doSomething() ).

    This is even true if you're calling the method from elsewhere in the class itself. If you are working in a non-static method (i.e. in an instance method), you would call this.doSomething().

提交回复
热议问题