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) { OptionaloptionalUser = Optional.ofNullable(null); if (optionalUser.isPresent()) { System.out.println("yes"); }else { System.out.println("no"); } OptionaloptionalUser1 = Optional.of(new User()); if (optionalUser1.isPresent()) { System.out.println(optionalUser1.get()); System.out.println("yes"); }else { System.out.println("no"); } } }