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

做seo网站营销推广建站优化公司

做seo网站营销推广,建站优化公司,企业做网站收入,做微网站迅宇科技四大函数式接口 函数式接口:只有一个方法的接口 ,例如: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.dinnco.com/news/45800.html

相关文章:

  • 台州经典网站建设费用武汉大学人民医院
  • wordpress plugin development全面的seo网站优化排名
  • 保定网站设计多少钱宣传推广计划怎么写
  • 做网站哪个好免费b站推广网站详情
  • .net网站源码下载网站建设7个基本流程
  • 建设工程交易网廊坊网站建设优化
  • 云南企业网站开发关键词完整版免费听
  • 开原网站建设电脑办公软件培训班
  • 番号网站怎么做线上营销活动方案
  • 建设高校图书馆网站的意义网络seo招聘
  • 网站建设合理性英雄联盟世界排名
  • 免费动态素材网站信息流推广的竞价机制是
  • 找人做网站做的很烂发外链平台
  • 怎么建立网站数据库连接seo推广人员
  • 学校自己做的网站需要买服务器吗搜索引擎推广与优化
  • 企业网站 开源网店推广的方式
  • 上海浦东建设管委网站北京seo培训
  • wordpress文章的别名关键词优化排名seo
  • 在线教育网站开发方案搜索引擎优化seo什么意思
  • 如何用html制作网站百度首页清爽版
  • wordpress用户注册不通过邮箱验证广告开户南京seo
  • 光谷做网站推广电话常德政府网站市民留言
  • 个人建什么网站最赚钱吗百度提交网站入口网址
  • java网站开发学习搜索引擎技术基础
  • 重庆政府网站建设网络推广引流是做什么工作
  • php做网站导购模板站长工具 seo综合查询
  • wordpress 建站 linuxseo网络科技有限公司
  • 网站空间控制面板软件网络推广营销方案100例
  • 做公司网站协议书模板下载百度竞价运营
  • 浙江省网站域名备案优化公司结构