| public class Demo { |
| |
| |
| public static void main(String[] args) { |
| |
| Inner inner = new Inner().invoke(); |
| Pojo1 p1 = inner.getP1(); |
| Pojo2 p2 = inner.getP2(); |
| |
| |
| System.out.println(p1.getContent() + p2.getContent()); |
| |
| } |
| |
| |
| public static class Pojo1 { |
| private String content; |
| |
| public Pojo1(String content) { |
| this.content = content; |
| } |
| |
| public String getContent() { |
| return content; |
| } |
| |
| public void setContent(String content) { |
| this.content = content; |
| } |
| } |
| |
| public static class Pojo2 { |
| private String content; |
| |
| public Pojo2(String content) { |
| this.content = content; |
| } |
| |
| public String getContent() { |
| return content; |
| } |
| |
| public void setContent(String content) { |
| this.content = content; |
| } |
| } |
| |
| private static class Inner { |
| private Pojo1 p1; |
| private Pojo2 p2; |
| |
| public Pojo1 getP1() { |
| return p1; |
| } |
| |
| public Pojo2 getP2() { |
| return p2; |
| } |
| |
| public Inner invoke() { |
| p1 = new Pojo1("p1"); |
| p2 = new Pojo2("p2") { |
| @Override |
| public String getContent() { |
| return "------------"; |
| } |
| }; |
| return this; |
| } |
| } |
| } |
| |
| |
| |