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

全球网站建设app拉新佣金排行榜

全球网站建设,app拉新佣金排行榜,泰州建设工程信息网,sql网站模板四大函数式接口 函数式接口:只有一个方法的接口 ,例如: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.mmbaike.com/news/90478.html

相关文章:

  • 哪里有网站建设加工免费招聘信息发布平台
  • 免费网站怎么制作电子商务网站有哪些?
  • iis 5 新建网站广告策划案优秀案例
  • 广告海外推广哈尔滨seo关键词排名
  • 做网站社区赚钱吗百度网盘客服电话
  • 小白建站软件互联网营销具体做什么
  • 其他公司盗用公司名做网站手机网络优化软件
  • 中企动力是干嘛的海口seo快速排名优化
  • 佛山品牌网站建设报价今日小说百度搜索风云榜
  • django做网站效率高吗网站seo优化有哪些方面
  • wordpress文章格式引用专业seo站长工具全面查询网站
  • 新昌网站建设培训机构连锁加盟
  • 企业的门户网站一般用什么做百度广告怎么做
  • 巫溪网站建设新闻网站软文平台
  • 网站开发下人员配置百度指数查询
  • 公安网站建设目的镇江网站
  • 云服务器wordpress如何上线网站排名优化软件联系方式
  • wordpress评论框加seo搜索工具栏
  • 如何建设一个web网站成人短期就业培训班
  • 微信小程序电商平台开发济南seo关键词优化方案
  • 怎么用VS2012建设网站黄页88网推广服务
  • 高校工会网站建设分销渠道
  • 时时彩网站开发公司宁波seo优化定制
  • 中国比较有名的公司杭州seo排名优化
  • 免费网站模板怎么做网站广州网站设计公司
  • 渭南网站建设推广百度识图搜索图片来源
  • 中文在线っと好きだっ最新版安卓aso关键词优化
  • 网页制作教程古诗词伊春seo
  • 金华网络推广公司福建seo排名
  • 性价比最高网站建设哪里好google seo是什么