阅读背景:

Java 8 新特性:6-Optional类

来源:互联网 

(原)

 先看看上面的说明:

/**
 * A container object which may or may not contain a non-null value.
 * If a value is present, {@code isPresent()} will return {@code true} and
 * {@code get()} will return the value.
 *Optional是一个容器对象,它可能包含,也可能不包含一个非空的值,如果这个值存在,isPresent方法将返回true,get方法将会返回它本身
 * <p>Additional methods that depend on the presence or absence of a contained
 * value are provided, such as {@link #orElse(java.lang.Object) orElse()}
 * (return a default value if value not present) and
 * {@link #ifPresent(java.util.function.Consumer) ifPresent()} (execute a block
 * of code if the value is present).
 *Optional提供一些额外的方法,这些方法依赖于它所包含的对象存在与否,例如orElse如果这个包含的对象不存在,将会返回一个默认值和ifPresent方法,如果包含的值存在,则会执行方法块中的内容
 * <p>This is a <a href="/go.html?url=../lang/doc-files/ValueBased.html">value-based</a>
 * class; use of identity-sensitive operations (including reference equality
 * ({@code ==}),  hash code, or synchronization) on instances of
 * {@code Optional} may have unpredictable results and should be avoided.
 *这是一个基于值的class类,对于同一性(特性)敏感的操作 (包含引用的相等性如:==),同一性的hashcode或者同步等等、对optional实例可能会产生不可预料的结果,这种结果应该被避免。
 * @since 1.8
 */
/**
 * A container objec



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: