Simple examples of commonly used chained call methods in Java and Android, javaandroid

Source: Internet
Author: User

Simple examples of commonly used chained call methods in Java and Android, javaandroid

This example describes the commonly used method of chained call in Java and Android. We will share this with you for your reference. The details are as follows:

Recently, many open-source frameworks in the fire have recently used a "(method ). (method ). (method) ", the most typical is RxJava. The source code of the AlertDialog control in android is also in this form. We can see that it is calledChain call. "Action is the only criterion for testing procedures" 0.0! After checking and speaking so much, you still have to write an example and run the expected results.

/***** Chained call ** @ author k. k **/public class Student {public Student () {} public static Builder builder () {return new Builder ();} // static internal class static class Builder {/* name */private String name;/* age */private String age;/* grade */private String grade; /* student ID */private String no;/* Major */private String Professional; public String getName () {return name;} public Builder setName (String name) {this. name = name; return this;} public String getAge () {return age;} public Builder setAge (String age) {this. age = age; return this;} public String getGrade () {return grade;} public Builder setGrade (String grade) {this. grade = grade; return this;} public String getNo () {return no;} public Builder setNo (String no) {this. no = no; return this;} public String getProfessional () {return Professional;} public Builder setProfessional (String professional) {Professional = professional; return this;} public void showMessagwe () {System. out. println ("name:" + this. name); System. out. println ("Age:" + this. age); System. out. println ("class:" + this. grade); System. out. println ("student ID:" + this. no); System. out. println ("professional:" + this. professional) ;}} public static void main (String [] args) {// chained call (simple code, strong readability) Student. builder (). setName ("always intended for attackers "). setAge ("23 "). setGrade ("Junior "). setNo ("20110310 "). setProfessional ("Information Management and Information System "). showMessagwe ();}}

Running result:

For more java-related content, refer to this topic: java data structure and algorithm tutorial, Java DOM node skills summary, Java file and directory operation skills summary, and Java cache operation skills Summary

I hope this article will help you with java programming.

Related Article

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.