JAVA中實現鏈式操作(方法鏈)的簡單例子

來源:互聯網
上載者:User

標籤:2.0   launch   set   exec   nashorn   date   api   帶來   pac   

使用鏈式編程帶來的簡單

student

package jetty;import java.util.stream.IntStream;/** * @Auther: Xiao Yu * @Date: Created in 14:52 2018/3/22 */public class Student {    private Integer id;    private Integer age;    private String  name;    private  String  address;    private  String  happy;    public Student getId() {        System.out.println(this.id);        return  this;    }    public Student setId(Integer id) {        this.id = id;        return  this;    }    public Student getAge() {        System.out.println(this.age);        return  this;    }    public Student setAge(Integer age) {        this.age = age;        return  this;    }    public Student getName() {        System.out.println(this.name);        return  this;    }    public Student setName(String name) {        this.name = name;        return  this;    }    public Student getAddress() {        System.out.println(this.address);        return  this;    }    public Student setAddress(String address) {        this.address = address;        return  this;    }    public Student getHappy() {        System.out.println(this.happy);        return  this;    }    public Student setHappy(String happy) {        this.happy = happy;        return  this;    }}

Test

package jetty;/** * @Auther: Xiao Yu * @Date: Created in 14:52 2018/3/22 */public class Test {    public static void main(String[] args) {        Student stu = new Student();        stu.setId(1).setAge(12).setName("小紅").setAddress("北京").setHappy("高興");        stu.getId().getAge().getName().getAddress().getHappy();    }}

控制台列印

E:\jdk\bin\java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=E:\ideat\IntelliJ IDEA 2016.3.2\bin" -Dfile.encoding=UTF-8 -classpath "E:\jdk\jre\lib\charsets.jar;E:\jdk\jre\lib\deploy.jar;E:\jdk\jre\lib\ext\access-bridge-32.jar;E:\jdk\jre\lib\ext\cldrdata.jar;E:\jdk\jre\lib\ext\dnsns.jar;E:\jdk\jre\lib\ext\jaccess.jar;E:\jdk\jre\lib\ext\jfxrt.jar;E:\jdk\jre\lib\ext\localedata.jar;E:\jdk\jre\lib\ext\nashorn.jar;E:\jdk\jre\lib\ext\sunec.jar;E:\jdk\jre\lib\ext\sunjce_provider.jar;E:\jdk\jre\lib\ext\sunmscapi.jar;E:\jdk\jre\lib\ext\sunpkcs11.jar;E:\jdk\jre\lib\ext\zipfs.jar;E:\jdk\jre\lib\javaws.jar;E:\jdk\jre\lib\jce.jar;E:\jdk\jre\lib\jfr.jar;E:\jdk\jre\lib\jfxswt.jar;E:\jdk\jre\lib\jsse.jar;E:\jdk\jre\lib\management-agent.jar;E:\jdk\jre\lib\plugin.jar;E:\jdk\jre\lib\resources.jar;E:\jdk\jre\lib\rt.jar;E:\Y2166\Quartz\target\classes;E:\maven\repository\org\quartz-scheduler\quartz\2.2.3\quartz-2.2.3.jar;E:\maven\repository\c3p0\c3p0\0.9.1.1\c3p0-0.9.1.1.jar;E:\maven\repository\org\slf4j\slf4j-api\1.7.7\slf4j-api-1.7.7.jar;E:\maven\repository\org\quartz-scheduler\quartz-jobs\2.2.1\quartz-jobs-2.2.1.jar;E:\maven\repository\org\springframework\spring-webmvc\4.1.8.release\spring-webmvc-4.1.8.RELEASE.jar;E:\maven\repository\org\springframework\spring-beans\4.1.8.RELEASE\spring-beans-4.1.8.RELEASE.jar;E:\maven\repository\org\springframework\spring-expression\4.1.8.RELEASE\spring-expression-4.1.8.RELEASE.jar;E:\maven\repository\org\springframework\spring-web\4.1.8.RELEASE\spring-web-4.1.8.RELEASE.jar;E:\maven\repository\org\springframework\spring-context\4.2.0.RELEASE\spring-context-4.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-aop\4.1.6.RELEASE\spring-aop-4.1.6.RELEASE.jar;E:\maven\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;E:\maven\repository\org\springframework\spring-core\4.1.6.RELEASE\spring-core-4.1.6.RELEASE.jar;E:\maven\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;E:\maven\repository\org\springframework\spring-context-support\3.2.4.RELEASE\spring-context-support-3.2.4.RELEASE.jar;E:\maven\repository\org\springframework\spring-tx\4.0.3.RELEASE\spring-tx-4.0.3.RELEASE.jar;E:\ideat\IntelliJ IDEA 2016.3.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain jetty.Test112小紅北京高興Process finished with exit code 0

 

JAVA中實現鏈式操作(方法鏈)的簡單例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.