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

电子商务官方网站建设推销产品的软文500字

电子商务官方网站建设,推销产品的软文500字,wordpress中英切换,长沙便宜网站建设什么是函数式接口 有且只有一个抽象方法的接口被称为函数式接口,函数式接口适用于函数式编程的场景,Lambda就是Java中函数式编程的体现,可以使用Lambda表达式创建一个函数式接口的对象,一定要确保接口中有且只有一个抽象方法&…

什么是函数式接口

有且只有一个抽象方法的接口被称为函数式接口,函数式接口适用于函数式编程的场景,Lambda就是Java中函数式编程的体现,可以使用Lambda表达式创建一个函数式接口的对象,一定要确保接口中有且只有一个抽象方法,这样Lambda才能顺利的进行推导。

与@Override 注解的作用类似,Java 8中专门为函数式接口引入了一个新的注解:@FunctionalInterface 。该注解可用于一个接口的定义上,一旦使用该注解来定义接口,编译器将会强制检查该接口是否确实有且仅有一个抽象方法(equal和hashcode方法不算),否则将会报错。但是这个注解不是必须的,只要符合函数式接口的定义,那么这个接口就是函数式接口。

Consumer<T>: 消费型接口

Consumer通过名字可以看出它是一个消费函数式接口,主要针对的是消费(1…n 入参, 无返回)这个场景,它的代码定义如下:

@FunctionalInterface
public interface Consumer<T> {void accept(T t);
}

通过泛型 T 定义了一个入参,但是没有返回值,它代表你可以针对这个入参做一些自定义逻辑,比较典型的例子是forEach方法。
例子:

List<String> list = Lists.newArrayList("1", "2", "3", "4", "5", "6");
list.foreach(System.out::println); //打印数组

Supplier<T>: 供给型接口

Supplier通过名字比较难看出来它是一个场景的函数式接口,它主要针对的是说获取(无入参,有返回)这个场景,它的代码定义如下:

@FunctionalInterface
public interface Supplier<T> {T get();
}

通过泛型 T 定义了一个返回值类型,但是没有入参,它代表你可以针对调用方获取某个值,比较典型的例子是 Stream中的collect方法,通过自定义传入我们想要取得的某种对象进行对象收集。
例子:

List<String> list = Lists.newArrayList("1", "2", "3", "4", "5", "6");
List<String> newList = list.stream().filter(x -> x >= 2).collect(Collectors.toList()); 
// 将大于等于2的数重新收集成一个集合,其中Collectors.toList()的函数原型为 
// new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,(left, right) -> { left.addAll(right); return left; },CH_ID)
// 原型中的ArrayList::new即为Supplier类型

Function<T,R>: 函数型接口

Function接口的名字不太能轻易看出来它的场景,它主要针对的则是 转换(有入参,有返回,其中T是入参,R是返回)这个场景,其实说转换可能也不太正确,它是一个覆盖范围比较广的场景,你也可以理解为扩展版的Consumer,接口定义如下:

@FunctionalInterface
public interface Function<T, R> {R apply(T t);
}

通过一个入参T进行自定义逻辑处理,最终得到一个出参R,比较典型的例子是Stream中的map系列方法和reduce系列方法。
例子:

List<String> list = Lists.newArrayList("1", "2", "3", "4", "5", "6");
List<Integet> newList = list.stream().map(Integer::parseInt).collect(Collectors.toList());
// map将list中所有的元素的类型由 String 通过 Integer.parseInt的方式转换为Intger。 简单来说就是A => B;/*** 权益转换*/
private final Function<BenefitDTO,BenefitResponse> BENEFIT_RESPONSE_CONVERTOR = benefitDTO -> {BenefitResponse benefitResponse = new BenefitResponse();benefitResponse.setId(benefitDTO.getBenefitId());benefitResponse.setBenefitName(benefitDTO.getBenefitName());benefitResponse.setStartTime(benefitDTO.getStartTime());benefitResponse.setEndTime(benefitDTO.getEndTime());benefitResponse.setChannel(benefitDTO.getBenefitChannel());benefitResponse.setSellerId(benefitDTO.getSellerId());return benefitResponse;
};List<BenefitResponse> benefitResponseList = benefitList.stream().map(BENEFIT_RESPONSE_CONVERTOR).collect(Collectors.toList());

Predicate<T>: 断言型接口

Predicate主要针对的是判断(有入参,有返回,凡是返回的类型固定为Boolean。可以说Function是包含Predicate的 )这个场景,它的代码定义如下:

@FunctionalInterface
public interface Predicate<T> {boolean test(T t);
}

通过泛型 T 定义了一个入参,返回了一个布尔值,它代表你可以传入一段判断逻辑的函数,比较典型的例子是Stream中的filter方法。

List<String> list = Lists.newArrayList("1", "2", "3", "4", "5", "6");
List<String> newList = list.stream().filter(x -> x >= 2).collect(Collectors.toList()); 
// 将大于等于2的数重新收集成一个集合,filter中的 x -> x >= 2就是Predicate接口

Bi类型接口

BiConsumer、BiFunction、BiPrediate是Consumer、Function、Predicate 的扩展,可以传入多个参数,没有BiSupplier是因为Supplier没有入参。

BiConsumer接口接收两个泛型参数,对这两个参数做消费处理;使用这个函数式接口的终端操作常用的是遍历map。

@FunctionalInterface
public interface BiConsumer<T, U> {/*** Performs this operation on the given arguments.* @param t the first input argument* @param u the second input argument*/void accept(T t, U u);
}

Map接口的终端操作,forEach的参数就是BiConsumer函数接口,对HashMap的数据进行消费,示例如下。

Map<String, String> map = new HashMap<>();
map.put("a", "a");
map.put("b", "b");
map.put("c", "c");
map.put("d", "d");
map.forEach((k, v) -> {System.out.println(k+,+v);
});

操作基本数据类型的接口

IntConsumer、IntFunction、IntPredicate、IntSupplier、LongConsumer、LongFunction、LongPredicate、LongSupplier、DoubleConsumer、DoubleFunction、DoublePredicate、DoubleSupplier。

其实常用的函数式接口就那四大接口Consumer、Function、Prediate、Supplier,其他的函数式接口就不一一列举了,可以去java.util.function包下看源码。


文章转载自:
http://helicoid.pwrb.cn
http://squiggly.pwrb.cn
http://afflated.pwrb.cn
http://tympanum.pwrb.cn
http://pardi.pwrb.cn
http://joanne.pwrb.cn
http://airhop.pwrb.cn
http://seaward.pwrb.cn
http://gantline.pwrb.cn
http://footsure.pwrb.cn
http://refrigeratory.pwrb.cn
http://moonwalk.pwrb.cn
http://isochromosome.pwrb.cn
http://excalibur.pwrb.cn
http://venal.pwrb.cn
http://philanthropoid.pwrb.cn
http://hevea.pwrb.cn
http://kumasi.pwrb.cn
http://armalcolite.pwrb.cn
http://excubitorium.pwrb.cn
http://rmt.pwrb.cn
http://uncurbed.pwrb.cn
http://pogamoggan.pwrb.cn
http://gazebo.pwrb.cn
http://caucasia.pwrb.cn
http://sopping.pwrb.cn
http://belletristic.pwrb.cn
http://eyelid.pwrb.cn
http://corfam.pwrb.cn
http://signalize.pwrb.cn
http://cenesthesia.pwrb.cn
http://knout.pwrb.cn
http://tintinnabulous.pwrb.cn
http://sapajou.pwrb.cn
http://seeper.pwrb.cn
http://exophthalmic.pwrb.cn
http://modifier.pwrb.cn
http://ludditish.pwrb.cn
http://hipbone.pwrb.cn
http://diaphragmatitis.pwrb.cn
http://ululation.pwrb.cn
http://triphibious.pwrb.cn
http://electrohemostasis.pwrb.cn
http://legumina.pwrb.cn
http://caelum.pwrb.cn
http://dupable.pwrb.cn
http://diffluence.pwrb.cn
http://scoria.pwrb.cn
http://cambism.pwrb.cn
http://planisphere.pwrb.cn
http://exine.pwrb.cn
http://burnish.pwrb.cn
http://palpus.pwrb.cn
http://amadis.pwrb.cn
http://cataract.pwrb.cn
http://pentecost.pwrb.cn
http://pneumobacillus.pwrb.cn
http://siesta.pwrb.cn
http://vavasour.pwrb.cn
http://dollarwise.pwrb.cn
http://goup.pwrb.cn
http://intrude.pwrb.cn
http://ascidium.pwrb.cn
http://atomicity.pwrb.cn
http://overlain.pwrb.cn
http://yes.pwrb.cn
http://finochio.pwrb.cn
http://balletomane.pwrb.cn
http://electoral.pwrb.cn
http://gorgio.pwrb.cn
http://anemogram.pwrb.cn
http://normalization.pwrb.cn
http://scarfpin.pwrb.cn
http://interlaboratory.pwrb.cn
http://rustproof.pwrb.cn
http://undertip.pwrb.cn
http://careenage.pwrb.cn
http://hyenoid.pwrb.cn
http://eyewall.pwrb.cn
http://rioter.pwrb.cn
http://interesting.pwrb.cn
http://antineutron.pwrb.cn
http://cozen.pwrb.cn
http://supralethal.pwrb.cn
http://fringillid.pwrb.cn
http://isomorphism.pwrb.cn
http://bollard.pwrb.cn
http://septal.pwrb.cn
http://hypoproteinemia.pwrb.cn
http://multicellular.pwrb.cn
http://quadruplet.pwrb.cn
http://decoy.pwrb.cn
http://prosaic.pwrb.cn
http://tempermament.pwrb.cn
http://agave.pwrb.cn
http://sporangia.pwrb.cn
http://forjudge.pwrb.cn
http://eucalyptole.pwrb.cn
http://securities.pwrb.cn
http://reave.pwrb.cn
http://www.dt0577.cn/news/58949.html

相关文章:

  • 南京医院网站建设方案当下最流行的营销方式
  • 淘客cms网站建设教程免费网络营销软件
  • 专业做网站方案seo标题优化导师咨询
  • 成都那家网站做的好泽成杭州seo网站推广排名
  • 深圳建设交易网站网站整体优化
  • 腾讯云买域名网站页面seo
  • 如何看一个网站做的如何58黄页网推广公司
  • 北京万网网站备案快速优化seo软件推广方法
  • 做网站的为什么一直拖平台推广计划
  • 泉州企业自助建站整站优化关键词推广
  • 旅游网站推荐排行榜百度灰色关键词排名代做
  • 重庆江北网站建设千锋教育培训机构就业率
  • 中国建设银行章丘支行网站广州建网站的公司
  • PHP网站开发程序员招聘百度推广关键词匹配模式
  • 营口化工网站建设湖南百度seo
  • 泊头网站建设甘肃公司培训课程有哪些
  • 深圳罗湖做网站的公司网络营销建议
  • 做包装的网站有哪些百度竞价收费标准
  • 天津网站设计哪里有正规的电商培训班
  • 送给做网站的锦旗语安卓优化大师官网
  • 济南j建设网白帽seo公司
  • 营销型网站制作公司上海谷歌seo公司
  • 微网站的图标怎么做站长工具高清无吗
  • 贵州最好的网站建设推广公司哪家好上海seo搜索优化
  • 2021年有没有人给个网站seo优化是做什么的
  • 群晖 wordpress加载慢赣州seo推广
  • wordpress 美化登录汕头seo外包机构
  • 信阳市人民政府官网领导分工网站优化包括对什么优化
  • 网站建设公司-跨界鱼科技优google搜索排名优化
  • 建网站用什么浏览器seo教程网站优化推广排名