您现在的位置是:主页 > news > 网站营销推广计划书/滨州网站seo

网站营销推广计划书/滨州网站seo

admin2025/5/24 20:30:17news

简介网站营销推广计划书,滨州网站seo,怎样php网站建设,wordpress 新变量为了应用不同的Lambda表达式&#xff0c;你需要一套能够描述常见函数描述符的函数式接口。Java API中已经提供了四大内置核心函数式接口 * JAVA8 内置的四大核心函数式接口 * * Consumer<T> :消费型接口 * void accept(T t); * Supplier<T> :供给型接口 *…

网站营销推广计划书,滨州网站seo,怎样php网站建设,wordpress 新变量为了应用不同的Lambda表达式&#xff0c;你需要一套能够描述常见函数描述符的函数式接口。Java API中已经提供了四大内置核心函数式接口 * JAVA8 内置的四大核心函数式接口 * * Consumer<T> :消费型接口 * void accept(T t); * Supplier<T> :供给型接口 *…

为了应用不同的Lambda表达式,你需要一套能够描述常见函数描述符的函数式接口。Java API中已经提供了四大内置核心函数式接口

 

* JAVA8 内置的四大核心函数式接口
*
* Consumer<T> :消费型接口
*          void accept(T t);
* Supplier<T> :供给型接口
*          T get();
* Function<T, R> :函数型接口
*          R apply(T t);
* Predicate<T>   :断言型接口
*          boolean test(T t);

一、Consumer<T>消费型接口

接收一个参数类型T,无返回值void

对类型为T的对象应用操作,包含方法void accept(T t);

@FunctionalInterface
public interface Consumer<T>{
void accept(T t);
    //Consumer<T> 消费型接口@Testpublic void test1(){happy(1000,(m) -> System.out.println("今天出去玩,花了"+m+"元"));}public void happy(double money, Consumer con){con.accept(money);}

运行结果:

今天出去玩,花了1000.0元

二、Supplier<T>供给型接口

参数类型无,返回类型T

返回类型为T的对象,包含方法T get();

@FunctionalInterface
public interface Supplier<T> {T get();
}
/*** @author Dongguo* @date 2021/8/14 0014 20:50* @description:产生指定个数的整数,并放入集合*/
public List<Integer> getNumList(int num, Supplier<Integer> s) {List<Integer> list =  new ArrayList<>();for (int i = 0; i <num; i++) {Integer integer = s.get();list.add(integer);}return list;
}@Test
public void test2() {List<Integer> numList = getNumList(10, () -> (int) (Math.random() * 100));for (Integer i:numList) {System.out.println(i);}
}

三、Function<T, R>函数型接口

参数类型T ,返回类型R

对类型为T的对象应用操作,并返回结果。结果是R类型的对象。包含方法R apply(T t);

@FunctionalInterface
public interface Function<T, R> {R apply(T t);
}
/*** @author Dongguo* @date 2021/8/14 0014 21:01* @description:用于处理字符串*/
public String strHandler(String s , Function<String,String> function){return function.apply(s);
}
@Test
public void test3() {String str= "abcdefg";String s = strHandler(str, (x) -> x.toUpperCase());System.out.println(s);
}

四、Predicate<T>断定型接口

参数类型T,返回类型为boolean

确定类型为T的对象是否满足某约束条件,并返回boolean值。包含方法 boolean test(T t);

@FunctionalInterface
public interface Predicate<T> {boolean test(T t);
}
//Predicate<T>   :断言型接口@Testpublic void test4(){List<String> list = Arrays.asList("Consumer","Supplier","Function","Predicate","haha","hai");List<String> filterStr = filterStr(list, (s) -> s.length() > 3);for (String str: filterStr){System.out.println(str);}}//需求: 将满足条件的字符串添加到集合中public List<String> filterStr(List<String> list,Predicate<String> pre){List<String> strList = new ArrayList<>();for (String str: list) {if (pre.test(str)){strList.add(str);}}return strList;}

运行结果:

Consumer
Supplier
Function
Predicate
haha

其他扩展函数式接口

JAVA8 内置的四大核心函数式接口能够满足大多数情景下的需求,当然如果觉得这几个还是不够用,那么可以参考下面的一些拓展的接口,其用法与上面大同小异:

序号接口 & 描述
1BiConsumer<T,U>

代表了一个接受两个输入参数的操作,并且不返回任何结果

2BiFunction<T,U,R>

代表了一个接受两个输入参数的方法,并且返回一个结果

3BinaryOperator<T>

代表了一个作用于于两个同类型操作符的操作,并且返回了操作符同类型的结果

4BiPredicate<T,U>

代表了一个两个参数的boolean值方法

5BooleanSupplier

代表了boolean值结果的提供方

6Consumer<T>

代表了接受一个输入参数并且无返回的操作

7DoubleBinaryOperator

代表了作用于两个double值操作符的操作,并且返回了一个double值的结果。

8DoubleConsumer

代表一个接受double值参数的操作,并且不返回结果。

9DoubleFunction<R>

代表接受一个double值参数的方法,并且返回结果

10DoublePredicate

代表一个拥有double值参数的boolean值方法

11DoubleSupplier

代表一个double值结构的提供方

12DoubleToIntFunction

接受一个double类型输入,返回一个int类型结果。

13DoubleToLongFunction

接受一个double类型输入,返回一个long类型结果

14DoubleUnaryOperator

接受一个参数同为类型double,返回值类型也为double 。

15Function<T,R>

接受一个输入参数,返回一个结果。

16IntBinaryOperator

接受两个参数同为类型int,返回值类型也为int 。

17IntConsumer

接受一个int类型的输入参数,无返回值 。

18IntFunction<R>

接受一个int类型输入参数,返回一个结果 。

19IntPredicate

:接受一个int输入参数,返回一个布尔值的结果。

20IntSupplier

无参数,返回一个int类型结果。

21IntToDoubleFunction

接受一个int类型输入,返回一个double类型结果 。

22IntToLongFunction

接受一个int类型输入,返回一个long类型结果。

23IntUnaryOperator

接受一个参数同为类型int,返回值类型也为int 。

24LongBinaryOperator

接受两个参数同为类型long,返回值类型也为long。

25LongConsumer

接受一个long类型的输入参数,无返回值。

26LongFunction<R>

接受一个long类型输入参数,返回一个结果。

27LongPredicate

R接受一个long输入参数,返回一个布尔值类型结果。

28LongSupplier

无参数,返回一个结果long类型的值。

29LongToDoubleFunction

接受一个long类型输入,返回一个double类型结果。

30LongToIntFunction

接受一个long类型输入,返回一个int类型结果。

31LongUnaryOperator

接受一个参数同为类型long,返回值类型也为long。

32ObjDoubleConsumer<T>

接受一个object类型和一个double类型的输入参数,无返回值。

33ObjIntConsumer<T>

接受一个object类型和一个int类型的输入参数,无返回值。

34ObjLongConsumer<T>

接受一个object类型和一个long类型的输入参数,无返回值。

35Predicate<T>

接受一个输入参数,返回一个布尔值结果。

36Supplier<T>

无参数,返回一个结果。

37ToDoubleBiFunction<T,U>

接受两个输入参数,返回一个double类型结果

38ToDoubleFunction<T>

接受一个输入参数,返回一个double类型结果

39ToIntBiFunction<T,U>

接受两个输入参数,返回一个int类型结果。

40ToIntFunction<T>

接受一个输入参数,返回一个int类型结果。

41ToLongBiFunction<T,U>

接受两个输入参数,返回一个long类型结果。

42ToLongFunction<T>

接受一个输入参数,返回一个long类型结果。

43UnaryOperator<T>

接受一个参数为类型T,返回值类型也为T。