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

温州大军建设有限公司网站app推广服务部

温州大军建设有限公司网站,app推广服务部,东莞网站建设网站,中国100强软件公司排名公布为了支持Java 8中的lambda表达式#xff0c;他们引入了Functional Interfaces。 具有单一抽象方法的接口可以称为功能接口。 Runnable#xff0c;Comparator#xff0c;Cloneable是功能接口的一些示例。 我们可以使用Lambda表达式实现这些功能接口。 例如#xff1a; Th… 为了支持Java 8中的lambda表达式他们引入了Functional Interfaces。 具有单一抽象方法的接口可以称为功能接口。 RunnableComparatorCloneable是功能接口的一些示例。 我们可以使用Lambda表达式实现这些功能接口。 例如 Thread t new Thread(new Runnable(){public void run(){System.out.println(Runnable implemented by using Lambda Expression);} }); 这是创建线程的旧方法。 由于Runnable具有单一抽象方法我们可以将其视为功能接口并且可以使用如下所示的Lambda表达式。 Thread t new Thread(()-{System.out.println(Runnable implemented by using Lambda Expression); }); 在这里我们没有传递Runnable对象而是传递了lambda表达式。 声明我们自己的功能接口 我们可以通过限定了S个英格尔一个 bstract M在接口ethod宣布我们自己的功能界面。 public interface FunctionalInterfaceTest{ void display(); } //Test class to implement above interface public class FunctionInterfaceTestImpl {public static void main(String[] args){//Old way using anonymous inner classFunctionalInterfaceTest fit new FunctionalInterfaceTest(){public void display(){System.out.println(Display from old way);}};fit.display();//outputs: Display from old way//Using lambda expressionFunctionalInterfaceTest newWay () - {System.out.println(Display from new Lambda Expression);}newWay.display();//outputs : Display from new Lambda Expression} } 我们可以使用FunctionalInterface注释进行注释以告知编译时错误。 它是可选的 例如 FunctionalInterface public interface FunctionalInterfaceTest{void display();void anotherDisplay();//shows an error, FunctionalInterface should have only one abstarct method. }默认方法 功能接口不能具有多个抽象方法但是可以具有多个默认方法。 Java 8中引入了默认方法以添加新方法进行接口而不会干扰已实现的类。 interface DefaultInterfaceTest{void show();default void display(){System.out.println(Default method from interface can have body..!);} } public class DefaultInterfaceTestImpl implements DefaultInterfaceTest{public void show(){System.out.println(show method);}//we dont need to provide any implementation to default method.public static void main(String[] args){DefaultInterfaceTest obj new DefaultInterfaceTestImpl();obj.show();//out puts: show methodobj.display();//outputs : Default method from interface can have body..!} } 默认方法的主要用途是不强制实现类我们可以向接口添加方法。 多重继承 如果两个接口中都存在相同的默认方法并且一个类正在实现该接口则它将引发错误。 //Normal interface with show methodinterface Test{default void show(){System.out.println(show from Test);}}//Another interface with same show methodinterface AnotherTest{default void show(){System.out.println(show from Test);}}//Main class to implement above two interfacesclass Main implements Test, AnotherTest{ //here is an ambiguity which show method has to inherit here } 此类不会编译因为Test和AnotherTest接口show方法之间存在歧义要解决此问题我们需要将Show方法覆盖到Main Class。 class Main implements Test, AnotherTest{void show(){System.out.println(Main show method);}}翻译自: https://www.javacodegeeks.com/2014/05/java-8-functional-interface-example.html
http://www.yutouwan.com/news/311531/

相关文章:

  • 自己如何做家政网站做网站为何要续费
  • 优秀网络广告案例分析wordpress优化检测
  • 石家庄信息门户网站定制费用跨平台 移动网站开发
  • 国内买机票最便宜网站建设本地访问wordpress
  • 网站网站建设的原则有哪些旅游公网站如何做
  • 东道设计公司待遇如何百度推广seo是什么意思
  • 做预算的网站域名最新通知
  • 给房地产公司做网站的公司网站建设中长出现的问题
  • 平台网站怎么做的好大学生html网页设计作业
  • 17网一起做网站友情链接交换系统
  • 安阳市建设工程领域网站Asp.net 手机网站制作
  • 干果坚果网站建设南宁百度seo推广
  • wordpress后台编辑主题时提示:抱歉_该文件无法被编辑软件优化
  • 励志故事网站源码电子商务网站建设影响因素
  • 郑州浩方网站建设智联招聘简易制作网站
  • 网站搜索功能怎么做如何查注册商标是别人注册过的
  • 极速彩票网站建设阿图什网站
  • 网站模板psd大兴网站建设多少钱
  • 西乡网站的建设福田我要做网站优化比较好
  • seo专员是什么意思上海网站seo优化
  • 网站建设需要购买服务器么网站建设用什么系统
  • 5星做号宿水软件的网站长沙第三方网站建设公司
  • 洛阳网站建设 恒凯科技判断网站cms
  • jsp做门户网站网站如何申请微信支付接口
  • 徐汇区网站建设公司分析一个网页设计
  • 做网站要开发嘛创新型的网站建设
  • asp 手机网站互联网公司上海
  • 安徽干部学校建设网站怎么在备案号添加网站
  • 湖南网站建设 系统wordpress 悬浮广告
  • 网站icp 备案查询木渎网站制作