Enforcing return type for an class that implements an interface

后端 未结 7 1279
青春惊慌失措
青春惊慌失措 2021-01-11 11:51

How do I enforce that the method getFoo() in the implementing class, returns a list of the type of same implementing class.

public interface Bar{
     ....
          


        
7条回答
  •  不思量自难忘°
    2021-01-11 12:47

    Maybe sth like this

    public interface Bar {
         ....
         List getFoo(); 
    }
    
    public class T implements Bar {
         List getFoo();
    }
    
    public class TestClass extends T {};
    

提交回复
热议问题