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

做那种事情的网站中国月球空间站

做那种事情的网站,中国月球空间站,重庆h5制作,网络推广外包公司在我以前的文章中#xff0c;我写了关于Function接口的内容 #xff0c;它是java.util.package的一部分。 我还提到了Predicate接口#xff0c;它是同一包的一部分#xff0c;在这篇文章中#xff0c;我将向您展示如何使用Predicate和Consumer接口。 让我们看一下Javadoc … 在我以前的文章中我写了关于Function接口的内容 它是java.util.package的一部分。 我还提到了Predicate接口它是同一包的一部分在这篇文章中我将向您展示如何使用Predicate和Consumer接口。 让我们看一下Javadoc for Predicate接口 确定输入对象是否符合某些条件。 在该接口中声明/定义了5种方法您一定想知道这是一个功能性接口 如果是那么您必须在继续之前阅读此方法这些方法是 //Returns a predicate which evaluates to true only if this predicate //and the provided predicate both evaluate to true. and(Predicate? super T p)//Returns a predicate which negates the result of this predicate. negate()//Returns a predicate which evaluates to true if either //this predicate or the provided predicate evaluates to true or(Predicate? super T p)//Returns true if the input object matches some criteria test(T t)//Returns a predicate that evaluates to true if both or neither //of the component predicates evaluate to true xor(Predicate? super T p) 除testT t以外的所有方法均为默认方法而testT t为抽象方法。 提供此抽象方法实现的一种方法是使用匿名内部类另一种方法是使用lambda表达式 。 用于消费者接口的Javadoc指出 接受单个输入参数且不返回结果的操作。 与大多数其他功能接口不同消费者应该通过副作用来操作。 此接口中有2种方法其中只有一种是抽象的而该抽象方法是acceptT t它接受输入并且不返回任何结果。 为了解释有关谓词和消费者界面的更多信息我们考虑一个带有名称等级和要支付费用的学生班。 每个学生都有一定的折扣折扣取决于学生的成绩。 class Student{String firstName;String lastName;Double grade;Double feeDiscount 0.0;Double baseFee 20000.0;public Student(String firstName, String lastName,Double grade) {this.firstName firstName;this.lastName lastName;this.grade grade;}public void printFee(){Double newFee baseFee - ((baseFee*feeDiscount)/100);System.out.println(The fee after discount: newFee);} } 然后创建一个接受Student对象谓词实现和Consumer实现的方法。 如果您不熟悉Function界面则应该花几分钟阅读此内容 。 此方法使用谓词来确定是否必须更新学生对费用的折扣然后使用Consumer实现来更新折扣。 public class PreidcateConsumerDemo {public static Student updateStudentFee(Student student,PredicateStudent predicate,ConsumerStudent consumer){//Use the predicate to decide when to update the discount.if ( predicate.test(student)){//Use the consumer to update the discount value.consumer.accept(student);}return student;}} 谓词和使用者中的测试方法和接受方法都分别接受声明的泛型类型的参数。 两者之间的区别在于谓词使用参数来做出某些决定并返回布尔值而Consumer使用参数来更改其某些值。 让我们看一下如何调用updateStudentFee方法 public static void main(String[] args) {Student student1 new Student(Ashok,Kumar, 9.5);student1 updateStudentFee(student1,//Lambda expression for Predicate interfacestudent - student.grade 8.5,//Lambda expression for Consumer inerfacestudent - student.feeDiscount 30.0);student1.printFee();Student student2 new Student(Rajat,Verma, 8.0);student2 updateStudentFee(student2,student - student.grade 8,student - student.feeDiscount 20.0);student2.printFee();} 在这篇文章中我通过示例解释了如何利用谓词和使用者接口它们是Java 8中引入的java.util.function包的一部分。 参考来自JCG合作伙伴 Mohamed Sanaulla的Java 8中java.util.function包中的谓词和使用者接口来自Experiences Unlimited博客。 翻译自: https://www.javacodegeeks.com/2013/04/predicate-and-consumer-interface-in-java-util-function-package-in-java-8.html
http://www.pierceye.com/news/21957/

相关文章:

  • php做的网站好么微信公众号运营策划方案
  • 专业网站开发平台做跨境电商亏死了
  • 新中建设公司招聘网站丽江网站开发找千素网
  • 网站建设基本步骤北京的餐饮网站建设
  • 河北云网站建设网站设计苏州
  • 手机网站模板使用方法wordpress页面编辑教程视频
  • 哪个网站可以搭建网页国家企业信息信用信息公示网山东
  • 手机触屏网站免费发帖推广
  • 做视频可以赚钱的网站树莓派wordpress速度慢
  • 衡阳 网络 网站电子商务网站建设项目的阶段的划分
  • 网站空间送域名ecilpse做网站
  • 1元购类似网站架设药多少钱atheme wordpress
  • 河北建设厅网站登陆怎么找附件网站商品图片尺寸
  • 中城投建设集团网站网站 优化 件
  • 百度做直播和短视频网站东莞连衣裙 东莞网站建设
  • 网站开发编程网站维护的协议
  • 做网站回答聊网站推广
  • 哈尔滨建站的网站网页网站建设技术分类
  • 某企业集团网站建设方案物流企业网站建设规划书
  • 网站推广流程是美心西饼在哪个网站做问卷调查
  • 网站icp不备案有关系吗wordpress忘记管理员密码
  • 卓成建设集团有限公司网站整站优化全网营销
  • 成都游戏网站建设自己做的网站怎么植入erp
  • 太仓住房与城乡建设局网站wordpress出现的问题
  • 推广网站文案素材大连网站建设lccm
  • 铜陵商城网站建设网站建设既有书籍又有光盘
  • 泉州建站平台营销技巧培训ppt
  • php网站后台模版wordpress开发工作流
  • 江门网站建设公司网站制作技术有哪些
  • 集团网站怎么建设平面设计师作品网站