Skip to content

Instantly share code, notes, and snippets.

@stream-iori
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save stream-iori/bf81de1861f6baa5316d to your computer and use it in GitHub Desktop.

Select an option

Save stream-iori/bf81de1861f6baa5316d to your computer and use it in GitHub Desktop.
Java8 lambda
//之前使用匿名类
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello world !");
}
}).start();
//现在使用lambda,无参数
new Thread(() -> System.out.println("Hello world !")).start();
//函数接口
@FunctionalInterface
public interface MyFn {
void method(String arg);
}
//使用函数接口
MyFn fn = arg -> System.out.println(arg);
fn.method("hello world");
//给个场景
Arrays.asList(1,2,3,4).forEach(e -> System.out.println(e % 2 == 0 ? "even" : "odd"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment