当前位置: 首页 > news >正文

做网站字号多大景观设计公司起名

做网站字号多大,景观设计公司起名,wordpress 招聘网站,新媒体营销工具有哪些四大函数式接口 函数式接口:只有一个方法的接口 ,例如:Runnable接口 Function 函数型接口,有一个输入参数,有一个输出 源码: /*** Represents a function that accepts one argument and produces a resul…

四大函数式接口

函数式接口:只有一个方法的接口 ,例如:Runnable接口

Function

函数型接口,有一个输入参数,有一个输出

源码:

/*** Represents a function that accepts one argument and produces a result.** This is a functional interface* whose functional method is apply(Object).** @param <T> the type of the input to the function* @param <R> the type of the result of the function** @since 1.8*/
@FunctionalInterface
public interface Function<T, R> {/*** Applies this function to the given argument.** @param t the function argument* @return the function result*/R apply(T t);

示例:

package function;import java.util.function.Function;/**** Function 函数型接口,有一个输入参数,有一个输出* 只要是函数式接口,就可以用lambda表达式*/
public class Demo01 {public static void main(String[] args) {// 匿名内部类,工具类,输出输入的结果
//        Function function = new Function<String,String>() {
//            @Override
//            public String apply(String s) {
//
//                return null;
//            }
//        };// 使用lambda表达式Function function = (str)->{return str;};System.out.println(function.apply("abc"));}
}

Predicate

断定型接口:只有一个输入参数,返回值为boolean

源码:

/*** Represents a predicate (boolean-valued function) of one argument.** This is a functional interface* whose functional method is test(Object).** @param <T> the type of the input to the predicate** @since 1.8*/
@FunctionalInterface
public interface Predicate<T> {/*** Evaluates this predicate on the given argument.** @param t the input argument* @return {@code true} if the input argument matches the predicate,* otherwise {@code false}*/boolean test(T t);

示例

package function;import java.util.function.Predicate;/**** 断定型接口:有一个输入参数,返回值为boolean*/
public class Demo02 {public static void main(String[] args) {// 判断字符串是否为空
//        Predicate predicate = new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                return s.isEmpty();
//            }
//        };// 函数型接口+lambda表达式,使代码看起来更加简洁Predicate<String> predicate = (s)->{return s.isEmpty();};System.out.println(predicate.test(""));}
}

Consumer

消费型接口,有一个参数,没有返回值

源码:

/*** Represents an operation that accepts a single input argument and returns no* result. Unlike most other functional interfaces, {@code Consumer} is expected* to operate via side-effects.** <p>This is afunctional interface* whose functional method is accept(Object).** @param <T> the type of the input to the operation** @since 1.8*/
@FunctionalInterface
public interface Consumer<T> {/*** Performs this operation on the given argument.** @param t the input argument*/void accept(T t);

示例

package function;import javax.lang.model.element.NestingKind;
import java.util.function.Consumer;/**** Consumer 消费型接口:只有输入,没有返回值*/
public class Demo03 {public static void main(String[] args) {
//        Consumer<String> consumer = new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        };Consumer<String> consumer = (s)->{System.out.println(s);};consumer.accept("asd");}
}

Supplier

供给型接口:没有参数,只有返回值

源码:

/*** Represents a supplier of results.** There is no requirement that a new or distinct result be returned each* time the supplier is invoked.** <This is a functional interface* whose functional method isget().** @param <T> the type of results supplied by this supplier** @since 1.8*/
@FunctionalInterface
public interface Supplier<T> {/*** Gets a result.** @return a result*/T get();
}

示例

package function;import java.util.function.Supplier;/**** 供给型接口:没有参数,只有返回值*/
public class Demo04 {public static void main(String[] args) {
//        Supplier<Integer> supplier = new Supplier<Integer>() {
//
//            @Override
//            public Integer get() {
//                return 1024;
//            }
//        };Supplier<Integer> supplier  = ()->{return 1024;};System.out.println(supplier.get());}
}

为什么要学习函数式接口?

  • 简化编程模型,使代码更加可读易懂

  • 在新版本的框架底层中,函数式接口有大量的应用

http://www.yayakq.cn/news/259320/

相关文章:

  • 建站公司常见提成比例有限公司注册流程
  • 网站系统模版星裕建设网站
  • 十堰城市建设网站设计好 英文网站
  • 深圳坑梓网站建设公司微信公众号登录入口在哪里
  • 贵阳花溪建设村镇银行官方网站wordpress段子
  • 网站seo优化合同极构网站建设工作室
  • 怎么给企业做网站百度网站app
  • 贵州建设学校网站wordpress文章末尾添加相关文章
  • 做外贸的免费网站有哪些辽宁省建设厅官方网站
  • 北京城乡与建设厅官方网站查询郑州站
  • 免备案做网站 可以盈利吗怎么把自己电脑建设网站
  • 瑞安做网站多少钱东莞国药官网网上商城
  • 网站怎样建设友情链接WordPress漏洞报告
  • 工信部网站登陆自己网站服务器
  • 网页设计介绍北京网站网站开发 实名认证需要备案吗
  • 一米八效果图网站pc 网站开发设计
  • 网站打不开被拦截怎么办百度应用搜索
  • 自己做优惠劵网站wordpress表格功能
  • 海外网站免费建设德宏网页设计
  • 网站建设工程属于科技档案吗网站建设和管理制度
  • 哈尔滨cms网站建设四川公司网站建设招标
  • 记事本做网站怎么加背景图wordpress 获取title
  • 滨州网站建设模板建设武进网站建设好么
  • 网站营销学多久WordPress 虎嗅主题免费
  • 济南做网站互联网公司用wordpress搭建商店
  • 英迈思做网站怎么样什么是百度搜索推广
  • 注册网站一年多少钱万宁市住房和城乡建设局网站
  • 戴尔网站建设的特点网站建设经典教材
  • 做网站 前端wordpress登入插件
  • 服装加工厂网站建设方案计划书华为净亏26亿