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

重庆 网站开发灰色行业关键词推广

重庆 网站开发,灰色行业关键词推广,功能网站,兰州头条今日头条新闻四大函数式接口 函数式接口:只有一个方法的接口 ,例如: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.15wanjia.com/news/7292.html

相关文章:

  • 新乡市网站建设百度快照推广排名
  • 深圳海洋网络做网站线上平台推广方案
  • 可以直接进入网站的正能量连接免费网络推广网址
  • 昆明网站建设哪家最好房地产最新消息
  • 大连模板网站制作费用外贸平台有哪些比较好
  • 怎么做下载类的网站宁波seo关键词
  • 免费制作企业宣传册制作工具seo搜索是什么
  • 网站页面大小优化怎么做手机百度账号登录入口
  • wordpress做一个html登陆页宁波seo深度优化平台有哪些
  • wordpress搜插件错误关键词优化排名费用
  • 乐从建网站制作网站大概多少钱
  • 易加互动平台seo人才
  • 企业网站建设可以分为哪些层次国内免费推广产品的网站
  • 做受视频网站 mcb3dbd抖音seo是什么
  • 文昌网站 做炸饺子windows优化大师的功能
  • 网站开发合同的缺陷链接提交工具
  • JSP 网站开发 视频百度云迅速上排名网站优化
  • 上海手机网站建设哪家好百度招聘电话
  • 有专做高端折扣女装的网站吗软文兼职10元一篇
  • 兰州市建设厅官方网站seo手机关键词网址
  • aspcms网络公司官方网站源码谷歌广告投放步骤
  • 如何进行网站运营与规划网络推广软文怎么写
  • 企业手机网站建设流程公司想做网络推广贵不
  • 用易语言做刷网站注册软件百度搜索seo优化技巧
  • wordpress建站要用模板吗人工智能的关键词
  • 新疆林业厅网站银川seo
  • access2003做网站网络推广费用预算表
  • 云南省建设监理协会网站湖南百度推广
  • 建设中医知识学习网站seo优化师培训
  • 推荐o2o网站建设企业网站推广的一般策略