1 Star 0 Fork 0

Gavin/on-java8

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FunctionVariants.java 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
Gavin 提交于 2020-12-27 21:02 +08:00 . ZhangGJ:Functional programming
package functional;
import java.util.function.*;
class Foo {
}
class Bar {
Foo f;
Bar(Foo f) {
this.f = f;
}
}
class IBaz {
int i;
IBaz(int i) {
this.i = i;
}
}
class LBaz {
long l;
LBaz(long l) {
this.l = l;
}
}
class DBaz {
double d;
DBaz(double d) {
this.d = d;
}
}
/**
* @Author ZhangGJ
* @Date 2020/12/27 15:41
*/
public class FunctionVariants {
static Function<Foo, Bar> f1 = f -> new Bar(f);
static IntFunction<IBaz> f2 = i -> new IBaz(i);
static LongFunction<LBaz> f3 = l -> new LBaz(l);
static DoubleFunction<DBaz> f4 = d -> new DBaz(d);
static ToIntFunction<IBaz> f5 = ib -> ib.i;
static ToLongFunction<LBaz> f6 = lb -> lb.l;
static ToDoubleFunction<DBaz> f7 = db -> db.d;
static IntToLongFunction f8 = i -> i;
static IntToDoubleFunction f9 = i -> i;
static LongToIntFunction f10 = l -> (int) l;
static LongToDoubleFunction f11 = l -> l;
static DoubleToIntFunction f12 = d -> (int) d;
static DoubleToLongFunction f13 = d -> (long) d;
public static void main(String[] args) {
Bar b = f1.apply(new Foo());
IBaz ib = f2.apply(11);
LBaz lb = f3.apply(11);
DBaz db = f4.apply(11);
int i = f5.applyAsInt(ib);
long l = f6.applyAsLong(lb);
double d = f7.applyAsDouble(db);
l = f8.applyAsLong(12);
d = f9.applyAsDouble(12);
i = f10.applyAsInt(12);
d = f11.applyAsDouble(12);
i = f12.applyAsInt(13.0);
l = f13.applyAsLong(13.0);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/letitgone/on-java8.git
git@gitee.com:letitgone/on-java8.git
letitgone
on-java8
on-java8
master

搜索帮助