Loading

Java 8 中的 java.util.Optional

Java 8 中的 java.util.Optional

学习了:https://blog.csdn.net/sun_promise/article/details/51362838

 

package com.stono.microservicesimpleprovideruser.controller;

import com.stono.microservicesimpleprovideruser.entity.User;

import java.util.Optional;

public class TestOptional {

    public static void main(String[] args) {
        Optional<User> optionalUser = Optional.ofNullable(null);
        if (optionalUser.isPresent()) {
            System.out.println("yes");
        }else {
            System.out.println("no");
        }
        Optional<User> optionalUser1 = Optional.of(new User());
        if (optionalUser1.isPresent()) {
            System.out.println(optionalUser1.get());
            System.out.println("yes");
        }else {
            System.out.println("no");
        }

    }
}

 

这个写的不错哦,学习了:http://www.importnew.com/6675.html 

 

posted @ 2018-04-03 13:09  stono  阅读(208)  评论(0编辑  收藏  举报