关于Idea IDE可以自动生成java代理的生产过程栗子

前端之家收集整理的这篇文章主要介绍了关于Idea IDE可以自动生成java代理的生产过程栗子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、新建一个java类,

package reusing;

<span style="color:#808080;">/*
<span style="color:#808080;"> Created by caoxiaohong on 16/11/20.
<span style="color:#808080;"> 测试idea可以手动选择生成代理
<span style="color:#808080;">
<span style="color:#808080;"> */
<span style="color:#000080;">public class SpaceShipDelegation {}

2、在要被代理的类,如下:

class SpaceShipControls{
    void up(int i){}
    void down(int i){}
    void left(int i){}
    void right(int i){}
    void forward(int i){}
    void back(int i){}
}

3、在类

public class SpaceShipDelegation {
    private SpaceShipControls controls=new SpaceShipControls();
}

显示如下:

选择Generate,后显示如下:

选择:Delegate Methods,然后显示如下:

选择ok,显示如下:

选择ok,显示如下:

这样就自动生成了java类的代理,也完成了idea自动生成java代理的过程。

sum:整体代码如下:

<pre style="font-family:Menlo;font-size:9pt;"><span style="color:#000080;">package reusing;

<span style="color:#808080;">/*
<span style="color:#808080;"> Created by caoxiaohong on 16/11/20.
<span style="color:#808080;"> 测试idea可以手动选择生成代理
<span style="color:#808080;">
<span style="color:#808080;"> */
<span style="color:#808080;">
<span style="color:#000080;">class SpaceShipControls{
<span style="color:#000080;">void up(<span style="color:#000080;">int i){}
<span style="color:#000080;">void down(<span style="color:#000080;">int i){}
<span style="color:#000080;">void left(<span style="color:#000080;">int i){}
<span style="color:#000080;">void right(<span style="color:#000080;">int i){}
<span style="color:#000080;">void forward(<span style="color:#000080;">int i){}
<span style="color:#000080;">void back(<span style="color:#000080;">int i){}
}
<span style="color:#000080;">public class SpaceShipDelegation {

<span style="color:#000080;"&gt;<strong>private </strong></span>SpaceShipControls <span style="color:#660e7a;"&gt;<strong>controls</strong></span>=<span style="color:#000080;"&gt;<strong>new </strong></span>SpaceShipControls();

<span style="color:#000080;"&gt;<strong>public void </strong></span>up(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.up(i);
}

<span style="color:#000080;"&gt;<strong>public void </strong></span>right(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.right(i);
}

<span style="color:#000080;"&gt;<strong>public void </strong></span>back(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.back(i);
}

<span style="color:#000080;"&gt;<strong>public void </strong></span>down(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.down(i);
}

<span style="color:#000080;"&gt;<strong>public void </strong></span>forward(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.forward(i);
}

<span style="color:#000080;"&gt;<strong>public void </strong></span>left(<span style="color:#000080;"&gt;<strong>int </strong></span>i) {
    <span style="color:#660e7a;"&gt;<strong>controls</strong></span>.left(i);
}

<span style="color:#808080;">/public static void main(String[] args){
<span style="color:#808080;">
<span style="color:#808080;"> }/
}

原文链接:https://www.f2er.com/idea/67288.html

猜你在找的IDEA相关文章