public class TestLambda {
static class Like2 implements ILike{
@Override
public void Lambda() {
System.out.println("I Like Lambda2");
}
}
public static void main(String[] args) {
ILike like = new Like();
like.Lambda();
like = new Like2();
like.Lambda();
class Like3 implements ILike{
@Override
public void Lambda() {
System.out.println("I Like Lambda3");
}
}
like = new Like3();
like.Lambda();
like = new ILike() {
@Override
public void Lambda() {
System.out.println("I Like Lambda4");
}
};
like.Lambda();
like = () -> {
System.out.println("I Like Lambda5");
};
like.Lambda();
}
}
interface ILike{
void Lambda();
}
class Like implements ILike{
@Override
public void Lambda() {
System.out.println("I Like Lambda");
}
}
练习
public class TestLambda2 {
static class Love2 implements ILove{
@Override
public void Love(int a) {
System.out.println("I Love You--->"+a);
}
}
public static void main(String[] args) {
ILove love = new Love();
love.Love(2);
love = new Love2();
love.Love(3);
class Love3 implements ILove{
@Override
public void Love(int a) {
System.out.println("I Love You--->"+a);
}
}
love = new Love3();
love.Love(4);
love = new ILove() {
@Override
public void Love(int a) {
System.out.println("I Love You--->"+a);
}
};
love.Love(5);
love = (int a) -> {
System.out.println("I Love You--->"+a);
};
love.Love(7);
love = (a) -> {
System.out.println("I Love You--->"+a);
};
love.Love(8);
love = a -> {
System.out.println("I Love You--->"+a);
};
love.Love(9);
love = a ->
System.out.println("I Love You--->"+a);
love.Love(10);
}
}
interface ILove{
void Love(int a);
}
class Love implements ILove{
@Override
public void Love(int a) {
System.out.println("I Love You--->"+a);
}
}
|