美文网首页SAP 修行
null in ABAP and nullpointer in

null in ABAP and nullpointer in

作者: _扫地僧_ | 来源:发表于2020-02-29 08:33 被阅读0次

    ABAP

    Java

    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的原创文章,请关注公众号"汪子熙":


    相关文章

      网友评论

        本文标题:null in ABAP and nullpointer in

        本文链接:https://www.haomeiwen.com/subject/nhyrhhtx.html