English 中文(简体)
Cantelli J 自动设立校正班。
原标题:Can IntelliJ automatically create a decorator class?

Sometimes, I create a decorator class like this:

class MyInterfaceDecorator implements MyInterface {
   private final MyInterface delegate;
   ... constructor taking a MyInterface instance ...

   @Override
   public Object someInterfaceMethod(Some argument) {
       return delegate.someInterfaceMethod(argument);
   }

   ... etc, more methods here...
}

Cantelli J为我自动创建这一类别?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 更新/

我注意到英特尔利J在产生代表方法方面有“基因”选择。 创建新类别:

public class MyDecoratorClass {
    private MyInterfaceWithManyMethods myInterface;
}

接着,我向Mendu > Code > 代表发表演讲。 方法,选择你想要总结的所有方法。

<>更新<>/>

你们可以尝试“证明”——和“替代与代表团的继承”的重新解释。 它应该能够这样做。 我称之为“Alt+Enter”

进入接口后,你希望产生一个矫正器。

public interface MyInterfaceWithManyMethods {
    void method1();
    void method2();
    void method3();
}

Press Alt+Enter, selected “Implement Interface”, given a name to the Decorator such as “MyDecorator”. 阁下

public class MyDecorator implements MyInterfaceWithManyMethods {
    public void method1() {
    }
    public void method2() {
    }
    public void method3() {
    }
}

在新类别中,选择阶级名称,然后选择“满意”和“与代表团替代继承”,选择你的接口,标明所有方法名称,进入媒体。 页: 1

public class MyDecorator {

    private final MyObject object = new MyObject();

    public void method1() {
        object.method1();
    }

    public void method2() {
        object.method2();
    }

    public void method3() {
        object.method3();
    }

    private class MyObject implements MyInterfaceWithManyMethods {
        public void method1() {

        }

        public void method2() {

        }

        public void method3() {

        }
    }
}

删除内层和物体初始剂。 您:

public class MyDecorator {


    public void method1() {
        object.method1();
    }

    public void method2() {
        object.method2();
    }

    public void method3() {
        object.method3();
    }

}

Press Alt+Enter on the “object” which is nowmark re, selected “Create field”, selected My InterfaceWithManyMethods.

public class MyDecorator {


    private MyInterfaceWithManyMethods object;

    public void method1() {
        object.method1();
    }

    public void method2() {
        object.method2();
    }

    public void method3() {
        object.method3();
    }

}

选择目标变量,新闻Alt+Enter, 选择“建筑参数”:

public class MyDecorator {


    private MyInterfaceWithManyMethods object;

    public MyDecorator(MyInterfaceWithManyMethods object) {
        this.object = object;
    }

    public void method1() {
        object.method1();
    }

    public void method2() {
        object.method2();
    }

    public void method3() {
        object.method3();
    }

}

你们看到,这一切都是用Alt+Enter的几颗中风进行的。 阅读像许多工作一样,但可以在不到20秒的时间内完成。 如果你仅采用2或3种方法,那么,如果你有多种复杂的签名方法,那么你就能够以这一方法取得大约20秒的工作成果。 Alt+Enter一只岩石:D

问题回答

You can perhaps add a file template like:

class ${NAME} implements ${INTERFACE} {
   private final ${INTERFACE} delegate;

   public ${NAME}(final ${INTERFACE} delegate) {
       this.delegate = delegate;
}

and then when you have created the file using this template, just use Alt+Inser and choice delegate Methods. It s not perfect, but this could be a shortcut





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签