lambda表达式

demo06
Person:

package edu.xcdq.demo6;

public class Person {
    
    private String name;
    private  int   age;

    public Person() {
    }

    public Person(String s, Integer integer) {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

Demo06:

package edu.xcdq.demo6;



@FunctionalInterface//表明函数式编程
interface IMymessage3{
    void print();
}

public class Dwmo06 {

    public static void main(String[] args) {

        IMymessage3 mymessage3 = ()-> System.out.println("MyMessage");
        mymessage3.print();



    }

}

TestDemo:

package edu.xcdq.demo6;

interface IMessage2{
    void print();
}

public class TestDemo {
    public static void main(String[] args) {
        IMessage2 message2 = new IMessage2() {//匿名内部类
            @Override
            public void print() {
                System.out.println("MyMessage");
            }
        };
        message2.print();
    }
}

testperson:


@FunctionalInterface
interface IMyPerson{
    public R message(PN name ,PA age);
}
public class testPerson {
    public static void main(String[] args) {
        IMyPerson shili;
        shili = (s, integer) -> new Person(s, integer);
        //Person::new 引用构造方法
        System.out.println(shili.message("eLonMask",45));
    }
}

Test01:


interface ImyMessage{
    R zhuanhuancanshu( P shili);
}

public class Test01 {
    public static void main(String[] args) {
        ImyMessage message = String::valueOf;
        String str = message.zhuanhuancanshu(100);
        System.out.println(str.length());
    }
}

Test02:



interface  IMyMessage2{
    R zhuanchengdaxie();
}
public class Test02 {

    public static void main(String[] args) {

        IMyMessage2 shili= "hello"::toUpperCase;
        System.out.println(shili.zhuanchengdaxie());

    }
}

Test3:

 */

@FunctionalInterface
interface IMyMessage6 {
    R compare(P p1, P p2);
}

public class Test3 {
    public static void main(String[] args) {
        IMyMessage6 message6 = String::compareTo;
        System.out.println(message6.compare("侯", "姚"));
    }
}

Test17:

@FunctionalInterface
interface  IMath{
    int add(int a , int b);
}


public class Test17 {

    public static void main(String[] args) {

        IMath math = Integer::sum;
        System.out.println(math.add(20,30));

    }

}

你可能感兴趣的:(lambda表达式)