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

毕业设计做网站答辩会问什么专业网站建设效果

毕业设计做网站答辩会问什么,专业网站建设效果,重庆网站制作长沙,免费广告设计软件前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。 Java8提倡函数式编程#xff0c;因而新增了一个函数式接口。函数式接口保证了函数式编程#xff0c;同时也保证了能够兼容以前的java版…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。 Java8提倡函数式编程因而新增了一个函数式接口。函数式接口保证了函数式编程同时也保证了能够兼容以前的java版本。 函数式接口的定义 在java8中满足下面任意一个条件的接口都是函数式接口 1、被FunctionalInterface注释的接口满足FunctionalInterface注释的约束。 2、没有被FunctionalInterface注释的接口但是满足FunctionalInterface注释的约束。 FunctionalInterface注释的约束 1、接口有且只能有个一个抽象方法只有方法定义没有方法体 2、在接口中覆写Object类中的public方法不算是函数式接口的方法。 下面三个接口都是函数式接口 //接口一 FunctionalInterface public interface FunctionInterfaceTest {String getInfo(String input);OverrideString toString();  //Object中的方法Overrideboolean equals(Object obj); //Object中的方法 } //接口二 FunctionalInterface public interface FunctionInterfaceTest {String getInfo(String input);}//接口三 public interface FunctionInterfaceTest {String getInfo(String input);} 函数式接口实例的创建 函数式接口实例的创建有三种方式1、lambda表达式2、方法引用3、构造方法引用。 public class Main {public static void main(String[] args) {/*** 1、lambda表达式* 这种形式最为直观lambda表达式接收一个String类型的参数返回一个String类型的结果。* 完全符合函数式接口FunctionInterfaceTest的定义*/FunctionInterfaceTest functionInterfaceTest1 item - item1;  /*** 2、方法引用* Main方法当中的getInstance和getMessage方法接收一个参数返回一个结果。符合函数式接口* FunctionInterfaceTest的定义。* 函数式接口只是定义了个方法的约定接收一个String类型的参数返回一个String类型的结果* 而对于方法内部进行何种操作则并没有做任何的限制。在这点上跟java以前的版本中的实现类与接口之间的* 关系很类似。不同的是函数式接口更偏重于计算过程约束了一个计算过程的输入和输出。* 这种约束计算过程的输入和输出的形式的好处可以看一下joinStr方法。*/FunctionInterfaceTest functionInterfaceTest2 Main::getInstance;  //方法引用FunctionInterfaceTest functionInterfaceTest3 Main::getMessage;  //方法引用String msg1 joinStr(你好,functionInterfaceTest2); //输出你好世界String msg2 joinStr(你好,functionInterfaceTest3); //输出世界你好System.out.println(msg1);System.out.println(msg2);//还有更简单的写法,高度抽象化具体处理由使用者自己决定String msg3 joinStr(你好,item -item世界); //输出你好世界String msg4 joinStr(你好,item -世界, item!); //输出世界你好System.out.println(msg3);System.out.println(msg4);/*** 3、构造方法引用* 构造函数的结构接收输入参数然后返回一个对象。这种约束跟函数式接口的约束很像。* 所以只要“输入参数类型”与“输出参数类型”跟FunctionInterfaceTest中的方法约束相同* 就可以创建出FunctionInterfaceTest接口的实例如下String的构造方法中有* new String(str)的构造方法所以可以得到实例。* 这里存在一个类型推断的问题JDK的编译器已经帮我们自动找到了只有一个参数且是String类型的构造方法。* 这就是我们直接String::new没有指定使用哪一个构造方法却可以创建实例的原因*/FunctionInterfaceTest functionInterfaceTest4 String::new; //方法引用}public static String getInstance(String item){return item世界;}public static String getMessage(String massage){return 世界, massage!;}public  static String joinStr(String str,FunctionInterfaceTest functionTest){return functionTest.getInfo(str);} java8中常用的函数式接口 常用的函数式接口主要有四种类型是通过其输入和输出的参数来进行区分的。定义了编码过程中主要的使用场景。 public class FunctionalInterfaceMain {public static void main(String[] args) {/*** 先看看如何创建它们*/FunctionString,String function1 item - item 返回值;ConsumerString function2 iterm - {System.out.println(iterm);};//lambda语句使用大括号没有return关键字表示没有返回值PredicateString function3 iterm - .equals(iterm);SupplierString function4 () - new String();/*** 再看看怎么使用* demo释义* 1、创建一个String类型的集合* 2、将集合中的所有元素的末尾追加字符串1* 3、选出长度大于2的字符串* 4、遍历输出所有元素*/ListString list Arrays.asList(zhangsan,lisi,wangwu,xiaoming,zhaoliu);list.stream().map(value - value 1) //传入的是一个Function函数式接口.filter(value - value.length() 2) //传入的是一个Predicate函数式接口.forEach(value - System.out.println(value)); //传入的是一个Consumer函数式接口}} 在实际使用中我们往往会输入多个参数而不是一个参数。针对于多个参数的计算最终都可以拆分两个参数的运算然后将两个参数的运算结合起来。如1234 10可以拆分为12 3,   336;   64 10 三个步骤完成(在java中是不允许一次返回多个值的)。 因此对于多个参数的操作也是如此。Java8中对于接收两个参数的场景提供了相关的函数式接口。如下 public class FunctionalInterfaceTest {public static void main(String[] args) {/*** Bi类型的接口创建*/BiFunctionString, String, Integer biFunction (str1,str2) - str1.length()str2.length();BiConsumerString, String biConsumer (str1,str2) - System.out.println(str1str2);BiPredicateString, String biPredicate (str1,str2) - str1.length() str2.length();/*** Bi类型的接口使用*/int length getLength(hello, world, (str1,str2) - str1.length() str2.length()); //输出10boolean boolean1 getBoolean(hello, world, (str1,str2) - str1.length() str2.length()); //输出falseSystem.out.println(length);System.out.println(boolean1);noResult(hello, world, (str1,str2) - System.out.println(str1 str2)); //没有输出}public  static int getLength(String str1,String str2,BiFunctionString, String, Integer function){return function.apply(str1, str2);}public static void noResult(String str1,String str2,BiConsumerString, String biConcumer){biConcumer.accept(str1, str2);}public static boolean getBoolean(String str1,String str2,BiPredicateString, String biPredicate){return biPredicate.test(str1, str2);} } 关于多个参数值的使用无论实在Function接口中还是在BI类型的接口都提供了类似的操作。注:java8中接口的方法是可以有实现的但需要default关键字修饰这是其他版本的jdk没有的特性 1、  Function接口的andThen方法和compose方法 源码 default V FunctionV, R compose(Function? super V, ? extends T before) {Objects.requireNonNull(before);return (V v) - apply(before.apply(v)); }default V FunctionT, V andThen(Function? super R, ? extends V after) {Objects.requireNonNull(after);return (T t) - after.apply(apply(t)); } 说明: Compose方法方法接收一个Function类型的参数返回一个值。这也是一个标准的Function类型的定义。在compose方法内部也有一个apply方法。在执行compose方法中的apply方法之前它先执行了before接口的apply方法也是compose方法的输入参数。然后将before方法执行的返回值作为compose中apply方法的输入参数。实际上是形成了一种链式组合。 andThen方法该方法与compose方法很类似。不同之处在于andThen是先执行自身的apply方法将apply的返回值作为after接口的输入值。相对于compose方法只是方向的不同 使用 public class FunctionalInterfaceTest {public static void main(String[] args) {String str1 getLength1(hello, value - hello的长度value, value - value.length()); //输出:hello的长度5System.out.println(str1);Integer result getLength2(hello, value - value, value - value.length()); //输出5System.out.println(result);}public  static String getLength1(String str1,FunctionInteger, String function1,FunctionString,Integer function2){/*** 这里一定要注意function1和function2的参数类型。* function2的输出类型与function1的输入类型一定要一致* 否则编译不会通过*/return function1.compose(function2).apply(str1);}public  static Integer getLength2(String str1,FunctionString, String function1,FunctionString,Integer function2){/*** 这里一定要注意function1和function2的参数类型。* function1的输出类型与function2的输入类型一定要一致(方向相反)* 否则编译不会通过*/return function1.andThen(function2).apply(str1);} } 相关接口BiFunction public static Integer getLength3(String str1,String str2,BiFunctionString, String, String biFunction,FunctionString,Integer function){/*** biFunction只有andThen方法这是有bi类型接口的特征决定的。* bi类型的接口需要接收两个参数然而java中是没有返回两个参数的情况的* 所以只有andThen方法且其参数是function类型的接收的是一个参数* 返回一个值*/return biFunction.andThen(function).apply(str1, str2); } 2、Consumer接口的andThen方法 源码 default ConsumerT andThen(Consumer? super T after) {Objects.requireNonNull(after);return (T t) - { accept(t); after.accept(t); }; } 说明        将输入参数分别赋给andThen内部的accept方法和after内部的accept方法。After的计算在andThen之后起到了后置连接的作用。在这里没有compose方法因为后置连接反过来就是前置连接所以不需要一个多余的compose方法了。只需要在传递时交换两个consumer的顺序即可。 使用 public class FunctionalInterfaceTest {public static void main(String[] args) {noResult(Integer.valueOf(12), value - {int num value 12;System.out.println(num);}, value - { int num value 24;System.out.println(num);}); //输出24,36}public static void noResult(Integer num,ConsumerInteger consumer1,ConsumerInteger consumer2){/*** 两个consumer的接收类型必须一致*/consumer1.andThen(consumer2).accept(num);} }  相关接口BiConsumer public static void noResultBi(Integer num1,Integer num2,BiConsumerInteger,Integer consumer1,BiConsumerInteger,Integer consumer2){/*** 两个consumer的接收类型必须一致*/consumer1.andThen(consumer2).accept(num1,num2); } 3、 predicate接口的and、or、negate方法 源码 default PredicateT and(Predicate? super T other) {Objects.requireNonNull(other);return (t) - test(t) other.test(t); }default PredicateT negate() {return (t) - !test(t); }default PredicateT or(Predicate? super T other) {Objects.requireNonNull(other);return (t) - test(t) || other.test(t); } 说明 源码已经很清晰了就不一一说明了。分别是, || 和取反操作。 使用 public class FunctionalInterfaceTest {public static void main(String[] args) {getBoolean(hello, value - value.length() 2, value - value.length() 6);}public static boolean getBoolean(String str1,Predicate String predicate1,Predicate String predicate2){boolean test predicate1.or(predicate2).test(str1);System.out.println(test); //输出truetest predicate1.and(predicate2).test(str1);System.out.println(test);//输出falsetest predicate1.negate().test(str1);System.out.println(test);//输出falsereturn test;} } 相关接口BiPreditcate public static  boolean getBooleanBi(String str1,String str2,BiPredicateString, String biPredicate1,BiPredicateString, String biPredicate2){boolean test biPredicate1.and(biPredicate2).test(str1, str2);test biPredicate1.negate().test(str1, str2);test biPredicate1.or(biPredicate2).test(str1, str2);return test; } 此外java8针对原生类型intlongdouble都提供了相应的函数式接口。如DoubleConsumer DoubleFunctionIntConsumer等等使用方式都相同见java.util.function包。 ———————————————— 本文为CSDN博主「漠风-」的原创文章遵循 CC 4.0 BY-SA 版权协议。
http://www.pierceye.com/news/509800/

相关文章:

  • 网新企业网站管理系统厦门好景科技做网站
  • 手机网站开发语言深圳网站建设培训
  • wordpress做的视听网站怎么用ftp清空网站
  • 网站建设能干什么网页设计代码模板人物介绍
  • 桂阳网站设计做p2p投资理财的网站
  • 做学术论文的网站从化专业做网站
  • 从化网站制作狮山公司网站建设
  • 网站开发验证码图片不显示php 自动做网站点击量
  • 大连网站开发费多少钱合肥企业网站建设工作室
  • 小企业网站建设的基础知识wap网站 开发
  • 地方门户网站赚钱吗沈阳黑酷做网站建设优化公司怎么样
  • 佛山市seo网站设计工具内部网站建设软件下载
  • 深圳网站建设高端设计网站建设 补充协议
  • 枣阳网站建设 枣阳山水数码自己建网站备案
  • 网站网站制作多少钱共享看世界新域名
  • 网站空间 阿里云wordpress多站点403
  • 下载网站备案的核验单免费ppt模板下载红色
  • discuz 网站备案信息代码温州网站建设优化公司
  • 外国人做汉字网站微网站开发手机模拟器
  • dede做网站网站群 优点
  • 网站制作多久能完成客户管理软件公司
  • 做网站最好的引流推广方法软件
  • 烟台网站建设4038gzs成都建设网上商城平台公司
  • 网站建设费在会计上怎么入账做学校网站的目的
  • 常德网站建设设计下载百度安装
  • 站长平台有哪些广东东远建设工程管理有限公司网站
  • 做蓝牙app的网站跨境电商是不是坑
  • 电子商务网站开发 刘兰娟企业网站建设发展平台
  • 天津做网站得公司游戏界面设计网站
  • 手机网站制作推广网站开发制作培训学校