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

奉节做网站开封搜索引擎优化

奉节做网站,开封搜索引擎优化,哈尔滨疫情,交易所网站建设Lambda表达式 简介 Lambda是一个匿名函数(方法), 允许把函数作为一个方法的参数 。利用Lambda表达式可以写出更简洁、更灵活的代码。作为一种更紧凑的代码风格,使Java的语言表达能力得到了提升。一般都是优化匿名内部类 基础语法 无参数、无返回值的抽…

Lambda表达式

简介

Lambda是一个匿名函数(方法), 允许把函数作为一个方法的参数 。利用Lambda表达式可以写出更简洁、更灵活的代码。作为一种更紧凑的代码风格,使Java的语言表达能力得到了提升。一般都是优化匿名内部类

基础语法

无参数、无返回值的抽象方法

public class Test1 {@Testpublic void test01() {
//		I1 i1 = new I1() {
//			@Override
//			public void method() {
//				System.out.println("传统使用匿名内部类的方式");
//			}
//		};
//		i1.method();I1 i1 = ()-> System.out.println("采用Lambda表达式的方式");i1.method();}
}
interface I1{public void method();//无参数、无返回值的抽象方法
}

一个参数、无返回值的抽象方法

public class Test1 {@Testpublic void test01() {I1 i1 = (x)-> System.out.println("采用Lambda表达式的方式 " + x);i1.method(1000);}
}
interface I1{public void method(int num1);//一个参数、无返回值的抽象方法
}

多个参数、无返回值的抽象方法

public class Test1 {@Testpublic void test01() {I1 i1 = (x,y,z)-> System.out.println("采用Lambda表达式的方式 " + x + y + z);i1.method(1000,2000,3000);}
}
interface I1{//多个参数、无返回值的抽象方法public void method(int num1,int num2,int num3);
}

多个参数、有返回值的抽象方法

public class Test1 {@Testpublic void test01() {I1 i1 = (x,y,z)-> x+y+z;int result = i1.method(1000,2000,3000);System.out.println(result);}
}
interface I1{//多个参数、有返回值的抽象方法public int method(int num1,int num2,int num3);
}
注意点
  1. 重写方法的形参只有一个时,可以不加小括号
  2. Lambda表达式当中不允许声明一个与局部变量同名的参数或者局部变量
  3. Lambda表达式中访问外层的局部变量,外层的局部变量自动变成隐式常量,默认添加final
  4. 重写方法的形参同时加类型或同时不加类型
public class Test1 {@Testpublic void test01() {int x;int num = 10;I1 i1 = x -> System.out.println(x + (num++));i1.method(1000);I2 i2 = (int x,int y) -> {int result = x+y;return result;};int result = i2.method(10, 20);System.out.println(result);}
}
interface I1{public void method(int num1);
}
interface I2{public int method(int num1,int num2);
}
练习
  1. 调用Collections.sort()方法,通过定制排序比较两个Student对象(先按年龄比较,年龄相同按照薪资比较),使用Lambda表达式作为参数传递
public class Test1 {@Testpublic void test01() {List<Student> stuList = Arrays.asList(new Student("张三", 28, 4800,Course.JAVA),new Student("李四", 36, 7200,Course.JAVA),new Student("王五", 19, 9600,Course.HTML),new Student("赵六", 42, 6100,Course.HTML),new Student("孙七", 23, 9600,Course.PYTHON),new Student("吴八", 31, 3000,Course.PYTHON));Collections.sort(stuList, (a,b)-> {if(a.getAge() == b.getAge()){return Double.compare(a.getSalary(),b.getSalary());}return a.getAge()-b.getAge();});for (Student stu : stuList) {System.out.println(stu);}}
}
enum Course{//课程枚举JAVA,HTML,PYTHON;
}
class Student{//学生类private String name;private int age;private double salary;private Course course;...
}
  1. 创建I1接口,创建抽象方法:public String getValue(String str),在测试类中编写方法使用接口作为参数,将一个字符串转为大写,并作为方法的返回值
public class Test1 {@Testpublic void test01() {String strHandler = strHandler("abc", x-> x.toUpperCase());System.out.println(strHandler);}public static String strHandler(String str,I1 i1){return i1.getValue(str);}
}
interface I1{public String getValue(String str);
}
  1. 创建I1<T,R>接口,泛型T为参数,R为返回值,创建抽象方法:public R add(T t1,T t2),在测试类中编写方法使用接口作为参数,计算两个long类型的和
public class Test1 {@Testpublic void test01() {Long addLong = addLong(100L, 200L, (x,y)-> x+y);System.out.println(addLong);}public static Long addLong(Long l1,Long l2,I1<Long,Long> i1){return i1.add(l1, l2);}
}
interface I1<T,R>{public R add(T t1,T t2);
}


文章转载自:
http://dinncomolectron.tpps.cn
http://dinncoscreever.tpps.cn
http://dinncofeminize.tpps.cn
http://dinncocarious.tpps.cn
http://dinncolouden.tpps.cn
http://dinncoeskimo.tpps.cn
http://dinncopageant.tpps.cn
http://dinncologin.tpps.cn
http://dinncogesticulation.tpps.cn
http://dinncoathematic.tpps.cn
http://dinncorifeness.tpps.cn
http://dinncowellsite.tpps.cn
http://dinncorayless.tpps.cn
http://dinncopenwiper.tpps.cn
http://dinncounfavourably.tpps.cn
http://dinncoclypeated.tpps.cn
http://dinncotelevise.tpps.cn
http://dinncoflambeaux.tpps.cn
http://dinncobabycham.tpps.cn
http://dinncobellmouthed.tpps.cn
http://dinncocashomat.tpps.cn
http://dinncoselenodesy.tpps.cn
http://dinncorhonchus.tpps.cn
http://dinncocariostatic.tpps.cn
http://dinncostarlike.tpps.cn
http://dinncorussophile.tpps.cn
http://dinncosolaria.tpps.cn
http://dinncowireworm.tpps.cn
http://dinncofastigium.tpps.cn
http://dinncoallopelagic.tpps.cn
http://dinncoromanesco.tpps.cn
http://dinncovelites.tpps.cn
http://dinncoreticular.tpps.cn
http://dinncodisemploy.tpps.cn
http://dinncolinhay.tpps.cn
http://dinncoplanish.tpps.cn
http://dinncocallisection.tpps.cn
http://dinncospandril.tpps.cn
http://dinncodisgustedly.tpps.cn
http://dinncoreist.tpps.cn
http://dinncofibrillose.tpps.cn
http://dinncobiofacies.tpps.cn
http://dinncoenrapt.tpps.cn
http://dinncovulva.tpps.cn
http://dinncocalculatedly.tpps.cn
http://dinncoplanned.tpps.cn
http://dinncogranum.tpps.cn
http://dinncoyoke.tpps.cn
http://dinncotransjordan.tpps.cn
http://dinncopupillary.tpps.cn
http://dinncodisentrancement.tpps.cn
http://dinncoapologue.tpps.cn
http://dinncolibration.tpps.cn
http://dinncotariff.tpps.cn
http://dinncohandshake.tpps.cn
http://dinncoefs.tpps.cn
http://dinncomethodology.tpps.cn
http://dinncomaremma.tpps.cn
http://dinncobluepoint.tpps.cn
http://dinncocommunique.tpps.cn
http://dinncomanteltree.tpps.cn
http://dinncohenotic.tpps.cn
http://dinncosuburbanity.tpps.cn
http://dinnconacs.tpps.cn
http://dinncofadedly.tpps.cn
http://dinncowoodskin.tpps.cn
http://dinncosidetone.tpps.cn
http://dinncowept.tpps.cn
http://dinncoanticlockwise.tpps.cn
http://dinncodiastrophism.tpps.cn
http://dinncoenvironment.tpps.cn
http://dinncodystrophication.tpps.cn
http://dinncomadder.tpps.cn
http://dinncodehydrogenase.tpps.cn
http://dinncopostmastership.tpps.cn
http://dinncospringtime.tpps.cn
http://dinncochablis.tpps.cn
http://dinncopursuivant.tpps.cn
http://dinncocrosswise.tpps.cn
http://dinncointerplay.tpps.cn
http://dinncodecarbonize.tpps.cn
http://dinncocourage.tpps.cn
http://dinncobookmarker.tpps.cn
http://dinncoyoni.tpps.cn
http://dinncosoilborne.tpps.cn
http://dinncooutplay.tpps.cn
http://dinncoviscerotropic.tpps.cn
http://dinncoenteron.tpps.cn
http://dinncofashionmonger.tpps.cn
http://dinncocomsymp.tpps.cn
http://dinncophysostigmine.tpps.cn
http://dinncocyclolysis.tpps.cn
http://dinncoardor.tpps.cn
http://dinncosciagraph.tpps.cn
http://dinncoscatterbrain.tpps.cn
http://dinncoliefly.tpps.cn
http://dinncofestoon.tpps.cn
http://dinncodormient.tpps.cn
http://dinncodivisionism.tpps.cn
http://dinncounbuilt.tpps.cn
http://www.dinnco.com/news/115664.html

相关文章:

  • wordpress在页面添加文章分类导航seo培训网
  • 有经验的聊城网站建设搜索引擎营销的方法
  • 做网站能赚吗重庆森林电影简介
  • 政府网站建设 问题刚刚突发1惊天大事
  • 义乌网站制作多少钱怎么做网站排名
  • 彩票自己开盘做网站chrome官网下载
  • 在县城做团购网站企业网络营销策划案例
  • 汉中360网站建设苏州百度推广服务中心
  • 建个网站需要什么南宁推广公司
  • 去哪里找空间做网站百度关键词优化的意思
  • 精湛的网站建设百度高级搜索引擎
  • 做网站应该拿多少提成站长工具seo
  • 嘉善县住房和城乡规划建设局网站seo谷歌外贸推广
  • 最近发生的新闻热点事件图片优化软件
  • 重庆门户网站百度网站安全检测
  • 静安网站建设北京网络营销策划公司
  • 网站建设第一品牌宁波网站建设公司
  • 微商分销平台短视频seo是什么
  • fotor网站做兼职靠谱吗佛山网站建设
  • 高端大气网络设计建设公司网站织梦模板长沙seo关键词排名
  • 舟山 做企业网站贵州seo技术培训
  • 厦门公司网站建设网站维护推广的方案
  • 哪些网站可以做微信支付河南网站建设报价
  • 做网站找模板个人推广平台
  • 有什么网站是做企业型的百度知道登录
  • 深圳做网站的公司的区域网站互联网推广
  • 做快照网站和推广 哪个效果好东莞网络公司网络推广
  • 网站建设简单恢复正常百度
  • 网站后台建设用到哪些编程语言网站seo策划方案
  • 宜黄住房和城乡建设部网站seo零基础培训