How to call static method from a generic class?

前端 未结 3 911
既然无缘
既然无缘 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:22

    The generic type can be specified in the class declaration:

    public class TestClass {
    
        public static  TestClass create() {
            return new TestClass();
        }
    }
    
    // Elsewhere in the code
    TestClass testClass = TestClass.create();
    

提交回复
热议问题