A simple example of implementing chained operations (method chains) in Java

Source: Internet
Author: User

Simple with chained programming

Student

 PackageJetty;ImportJava.util.stream.IntStream;/*** @Auther: Xiao Yu * @Date: Created in 14:52 2018/3/22*/ Public classStudent {PrivateInteger ID; PrivateInteger age; PrivateString name; PrivateString address; PrivateString Happy;  PublicStudent getId () {System.out.println ( This. ID); return   This; }     PublicStudent setId (Integer id) { This. ID =ID; return   This; }     PublicStudent getage () {System.out.println ( This. Age); return   This; }     PublicStudent setage (Integer age) { This. Age =Age ; return   This; }     PublicStudent GetName () {System.out.println ( This. Name); return   This; }     PublicStudent setName (String name) { This. Name =name; return   This; }     PublicStudent getaddress () {System.out.println ( This. Address); return   This; }     PublicStudent setaddress (String address) { This. Address =address; return   This; }     PublicStudent gethappy () {System.out.println ( This. Happy); return   This; }     PublicStudent Sethappy (String happy) { This. Happy =Happy; return   This; }}

Test

 Package Jetty; /**  */Publicclass  Test    {publicstaticvoid  Main (string[] args) {        new  Student ();        Stu.setid (1). Setage () setName ("Xiao Hong"). Setaddress ("Beijing"). Sethappy ("Happy");        Stu.getid (). Getage (). GetName (). GetAddress (). Gethappy ();}    }

Console printing

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 Little Red Beijing happy process finished with exit code 0

A simple example of implementing chained operations (method chains) in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.