CODEARTS IDE-尽可能使用Interface:重构后

时间:2024-04-16 15:05:26

重构后

class UseInterface {

    public static void main(String[] args) {
        InnerInterface innerInterface = new InnerClass();
        print(innerInterface);
    }

    private static void print(InnerInterface innerInterface) {
        innerInterface.print();
    }

    private static class InnerClass implements InnerInterface {
        @Override
        public void print() {
            System.out.println("Hello World!");
        }
    }

    private static interface InnerInterface{
        void print();
    }
}
support.huaweicloud.com/usermanual-codeartside/codeartside_01_0155.html