Use methods declared in implementation that are not defined in interface

后端 未结 6 1805
不知归路
不知归路 2020-12-18 11:56

I have a class defined by an interface

public interface Test {
    void testMethod();
}

Test test = new TestImpl();

public class TestImpl implements Test {         


        
6条回答
  •  情话喂你
    2020-12-18 12:48

    Of course you can access your methods as was answered above, but you should adhere to best practices in programming. So you if you can't add required methods to Interface1 create Interface2 that extends Inteface1 and finally add your methods.

提交回复
热议问题