什么做书籍的网站好,知名商城网站建设报价,婚恋网注册,钢材料 网站建设 中企动力使用一个私有构造函数创建一个抽象类,并在类中嵌套“数据构造函数”(左侧和右侧静态工厂方法),以便它们可以看到私有构造函数,但没有其他任何东西可以有效地密封类型.使用抽象方法either来模拟详尽的模式匹配,在静态工厂方法返回的具体类型中适当地覆盖.实现便利方法(如fromLef…使用一个私有构造函数创建一个抽象类,并在类中嵌套“数据构造函数”(左侧和右侧静态工厂方法),以便它们可以看到私有构造函数,但没有其他任何东西可以有效地密封类型.使用抽象方法either来模拟详尽的模式匹配,在静态工厂方法返回的具体类型中适当地覆盖.实现便利方法(如fromLeft,fromRight,bimap,first,second).import java.util.Optional;import java.util.function.Function;public abstract class Either {private Either() {}public abstract C either(Function super A, ? extends C left,Function super B, ? extends C right);public static Either left(A value) {return new Either() {Overridepublic C either(Function super A, ? extends C left,Function super B, ? extends C right) {return left.apply(value);}};}public static Either right(B value) {return new Either() {Overridepublic C either(Function super A, ? extends C left,Function super B, ? extends C right) {return right.apply(value);}};}public Optional fromLeft() {return this.either(Optional::of, value - Optional.empty());}// other convenience methods}愉快又安全没办法搞砸了.关于您尝试上课的问题Left L扩展要么 L,,考虑签名 A,B A,B左(一个值).类型参数B未出现在参数列表中.因此,给定某种类型A的值,您可以获得Either A,B适用于任何类型B.