使用链式编程带来的简单
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
packagejetty;/*** @Auther: Xiao Yu
* @Date: Created in 14:52 2018/3/22*/
public classTest {public static voidmain(String[] args) {
Student stu= newStudent();
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.Test
1
12
小红
北京
高兴
Process finished with exit code 0