2021-05-12

课堂代码

public class Demo01 {
    @FunctionalInterface  //表明函数式编程
    interface IMymessage3{
        void print();
    }
    public static class Test16{
        public static void main(String[] args) {
            IMymessage3 mymessage3 = ()-> System.out.println("MyMessage");
            mymessage3.print();
        }
    }
}
public class Person {
    private String name;
    private Integer age;

    public Person(String s, Integer integer) {
    }

    public String getName() {
        return name;
    }

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

    public Integer getAge() {
        return age;
    }

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

    public Person(){

    }
}

interface  Imyessage<P,R >{
    R zhuanhuancanshu(P shili);
}
public class Test01 {
    public static void main(String[] args) {
        Imyessage<Integer,String >message = String::valueOf;
        String str = message.zhuanhuancanshu(100);
        System.out.println(str.length());
    }
}

import java.util.Locale;

interface IMyMessage2<R>{
    R zhuanchengdaxie();
}
public class Test02 {
    public static void main(String[] args) {
        //"hello"::toUpperCase;
        IMyMessage2 <String> shili = "hello"::toUpperCase;
        System.out.println(shili.zhuanchengdaxie());

    }
}

interface IMyMessage6<R,P>{
    R compare(P canshu1 , P canshu2);
}
public class Test03 {
    public static void main(String[] args) {
        IMyMessage6<Integer,String >shili = String::compareTo;;
        System.out.println(shili.compare("b","a"));

    }
}

@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));
    }
}


public class TestDemo {
    @FunctionalInterface
    interface Imessage{
        public void print();
    }
    public static class testDemo{
        public static void main(String[] args) {
            Imessage message = () ->{
                System.out.println("hello");
                System.out.println("world");
                System.out.println("heillo,world");
            };
            message.print();
        }
    }
}

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

    }
}

import java.io.File;
import java.io.IOException;

public class Main {
    public static    void main(String[] args) {
        File file =  new File("D:\\classthree.txt");
        File file1 = new File("d:/three.txt");
        File file2 = new File("d:/ch10/demo01");
        File file3 = new File("d/ch010");
        try {
            file.createNewFile();
            file1.createNewFile();
            file2.mkdir();//文件夹
            /*file2.mkdirs(); // 创建多层文件夹
            file3.mkdir();  // 创建一层文件夹
            file1.delete(); // 删除一个文件
            file2.delete(); // 删除为空的一级文件夹
            file3.renameTo(new File("d/ch0010"));//修改路径*/
            System.out.println(file.exists());
            System.out.println(file.exists());
            System.out.println(file2.isDirectory());
            System.out.println(file2.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容