null in ABAP and nullpointer in Java_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > null in ABAP and nullpointer in Java

null in ABAP and nullpointer in Java

 2020/6/28 16:09:51  JerryWang_SAP  程序员俱乐部  我要评论(0)
  • 摘要:ABAPJavaclassOuter{Nestednested;NestedgetNested(){returnnested;}publicOuter(){//nested=newNested();}}classNested{Innerinner;InnergetInner(){returninner;}publicNested(){//inner=newInner();}}classInner{Stringfoo="Jerry";StringgetFoo(){returnfoo;}
  • 标签:Java

ABAP

class="origin_image zh-lightbox-thumb lazy" width="982" alt="" src="/Upload/Images/2020062816/B7C83044B6A4D6D5.jpg">

Java

monospace; font-size: inherit; background-color: inherit;" class="language-text">class Outer {
    Nested nested;
    Nested getNested() {
        return nested;
    }
    
    public Outer(){
    	// nested = new Nested();
    }
}
class Nested {
    Inner inner;
    Inner getInner() {
        return inner;
    }
    
    public Nested() {
    	// inner = new Inner();
    }
}

class Inner {
    String foo = "Jerry";
    String getFoo() {
        return foo;
    }
}

?

为了打印嵌套层数很深的foo:

# 2B青年的写法

public void test1(){
		Outer outer = new Outer();
		if (outer != null && outer.nested != null && outer.nested.inner != null) {
		    System.out.println(outer.nested.inner.foo);
		}
	}

?

# 文艺青年的写法

public void test2(){
		Optional.of(new Outer()).map(Outer::getNested).map(Nested::getInner).map(Inner::getFoo)
			.ifPresent(System.out::println);
	}

More discussion of ABAP, Java and JavaScript could be found from my Wechat article Jerry的ABAP, Java和JavaScript乱炖:?Jerry的ABAP, Java和JavaScript乱炖

上一篇: 【赵强老师】大数据工作流引擎Oozie 下一篇: 没有下一篇了!
发表评论
用户名: 匿名