How to call static method from a generic class?

前端 未结 3 914
既然无缘
既然无缘 2021-01-16 13:46

I have a class containing a static create method.

public class TestClass {

 public static  TestClass create() {
    return new TestClass&l         


        
3条回答
  •  一个人的身影
    2021-01-16 14:24

    Yeah, that's pretty... unintuitive.

    A sidenote from Josh Bloch's presentation of his Effective Java, 2nd Edition about the issue: "God kills a kitten every time you specify an explicit type parameter". I would like to avoid constructs like this but sometimes it cannot be evaded.

    The trick is to specify the generic parameter after the . character: TestClass.create().

提交回复
热议问题