File tree Expand file tree Collapse file tree
modules/src/main/java/com/platzi/functional_student_practice/_10_chaining Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .platzi .functional_student_practice ._10_chaining ;
2+
3+
4+ public class C20Chaining {
5+ public static void main (String [] args ) {
6+ System .out .println ("////////////////////////////////////////////////////////////////////////////////////" );
7+ System .out .println ("\n CLASS 20\n " );
8+
9+ // 1. Every .append() method returns "this" object with the changes updated in state.
10+ StringBuilder stringBuilder = new StringBuilder ();
11+ stringBuilder .append ("Hola " )
12+ .append ("alumno" )
13+ .append ("!" )
14+ .reverse ()
15+ .append (" :iztalP" )
16+ .reverse ();
17+ System .out .println (stringBuilder );
18+
19+ // 2. Custom example. This is usefull with FUNCTION COMPOSITION
20+ Chainer chainer = new Chainer ();
21+ Chainer chainer2 = chainer .sayHi ();
22+ Chainer chainer3 = chainer2 .sayBye ();
23+ chainer3 .sayHi ().sayBye ();
24+ }
25+
26+ private static class Chainer {
27+ public Chainer sayHi () {
28+ System .out .println ("Hola" );
29+ return this ;
30+ }
31+
32+ public Chainer sayBye () {
33+ System .out .println ("Bye" );
34+ return this ;
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments