在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

JAVA语义增强:Style

2017-2-9 13:05| 发布者: zhangjf| 查看: 538| 评论: 0

摘要: Style 给 Java 8 带来其他语言高效的编程风格。 Style 通过精心挑选的方法/类名来模拟其他语言。 Style 致力于让你的编码更加美观,进行更少的重复编码,以及提升可读性。 代码示例: // define a function to se ...

Style 给 Java 8 带来其他语言高效的编程风格。

Style 通过精心挑选的方法/类名来模拟其他语言。

Style 致力于让你的编码更加美观,进行更少的重复编码,以及提升可读性。

代码示例:

  1. // define a function to see if list contain a person with given name:
  2. def<Boolean> check = $(
  3. (List<Person> ls, String name) -> null != $(list).forEach(e -> {
  4. if (e.name().equals(name))
  5. return true;
  6. return null;
  7. }));
  8. check.apply(list, "cass");
  9. // If expression with return value:
  10. System.out.println(If(
  11. $(list).findOne(e -> e.name().equals("cass")),
  12. res -> {
  13. return res.id();
  14. }).Else(() -> "Not Found!"));
  15. // forEach with iterator info
  16. $(list).forEach((e, i) -> System.out.println(
  17. "Element is:" + e + " Index is:" + $(i)));
  18. // dozens of new features waiting for you to explore.
复制代码

项目主页:http://www.open-open.com/lib/view/home/1440314626867

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-9 21:36

Copyright 2015-2025 djqfx

返回顶部