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

莒南县网站建设seo站长工具综合查询

莒南县网站建设,seo站长工具综合查询,有哪些好的做h5的网站,青州网站建设青州2 方法引用 在使用Lambda表达式的时候,我们实际上传递进去的代码就是一种解决方案:拿参数做操作那么考虑一种情况: 如果我们在Lambda中所指定的操作方案,已经有地方存在相同方案,没有必要再写重复逻辑,如usePrintable…

2 方法引用

  • 在使用Lambda表达式的时候,我们实际上传递进去的代码就是一种解决方案:拿参数做操作
  • 那么考虑一种情况: 如果我们在Lambda中所指定的操作方案,已经有地方存在相同方案,没有必要再写重复逻辑,如usePrintable(s -> System.out.println(s));中System.out.println(s)就是重复逻辑
  • 可以通过方法引用来使用已经存在的方案

2.1 方法引用符

  • 方法引用符

    • :: 该符号为引用运算符,而它所在的表达式被称为方法引用
  • 对比分析

    • Lambda表达式usePrintable(s -> System.out.println(s));
      分析:拿到参数s之后通过Lambda表达式,传递给System.out.println()方法去处理
    • 方法引用usePrintable(System.out:println);//隐含了把s参数给println方法
      分析:直接使用System.out中的println方法来取代Lambda,代码更加的简洁
  • 推导与省略

    • 如果使用Lambda,那么根据"可推导就是可省略”的原则,无需指定参数类型,也无需指定的重载形式,它们都将被自动推导
    • 如果使用方法引用,也是同样可以根据上下文进行推导
    • 方法引用是Lambda的李生兄弟(可以使用Lambda表达式就可以使用方法引用)
  • 范例

package test;public class Demo {public static void main(String[] args) {//Lambda表达式usePrintable(i -> {System.out.println(i); //888});//方法引用usePrintable(System.out::println); //888}private static void usePrintable(Printable p) {p.printInt(888);}
}

2.2 引用类方法

  • 常用方法引用

    • 引用类方法
    • 引用类的实例方法(成员方法)
    • 引用对象的实例方法
    • 引用构造器
  • 引用类方法,其实就是引用类的静态方法

  • 格式类名::静态方法

  • 范例Integer::parselnt
    Integer类的方法:public static int parseInt(String s)将此String转换为int类型数据

  • 练习
    在这里插入图片描述

  • 接口类

package test;public interface Converter {int convert(String s);
}
  • 测试类
package test;public class Demo {public static void main(String[] args) {
//        useConverter(s -> {
//            return Integer.parseInt(s);
//        });useConverter(s -> Integer.parseInt(s)); //666//引用类方法useConverter(Integer::parseInt); //666//Lambda表达式被类方法替代时,他的形式参数全部传给静态方法做参数;如s字符串传递给parseInt方法}private static void useConverter(Converter c) {int number = c.convert("666");System.out.println(number);}
}

2.3 引用类的实例方法(成员方法)

  • 引用类的实例方法,其实就是引用类中的成员方法

  • 格式类名::成员方法

  • 练习
    在这里插入图片描述

  • 接口

package test;public interface MyString {String mySubString(String s,int x,int y);
}
  • 测试类
package test;public class Demo {public static void main(String[] args) {
//        useMyString((String s,int x,int y)->{
//            return s.substring(x, y); //llo
//        });useMyString((s,x,y)-> s.substring(x, y)); // //llo//引用类中的实例方法useMyString(String::substring); //llo//Lambda表达式中的形式参数(s,x,y)//第一个参数作为调用者//后面的参数全部传给实例方法作为参数}public static void useMyString(MyString m) {String s = m.mySubString("HelloWorld", 2, 5);System.out.println(s);}
}

2.4 引用对象的实例方法(成员方法)

  • 引用对象的实例方法,其实就引用类中的成员方法

  • 格式对象名::成员方法

  • 范例"HelloWorld"::toUpperCase
    String类中的方法:public String toUpperCase()将此String所有字符转换为大写

  • 练习
    在这里插入图片描述

  • PrintString类

package test;public class PrintString {//把字符串转换成大写public void printUpper(String s) {String result = s.toUpperCase();System.out.println(result);}
}
  • 接口
package test;public interface Printer {void printUpperCase(String s);
}
  • 测试类
package test;public class Demo {public static void main(String[] args) {
//        usePrinter((String s ) -> {
            String result = s.toUpperCase();
            System.out.println(result); //HELLO
//            System.out.println(s.toUpperCase());
//        });usePrinter(s -> System.out.println(s.toUpperCase()));//引用对象的实例方法PrintString ps = new PrintString();usePrinter(ps::printUpper); //HELLO}public static void usePrinter(Printer p) {p.printUpperCase("hello");}
}

2.5 引用构造器

  • 引用构造器,就是引用构造方法

  • 格式类名::new

  • 范例Student::new

  • 练习
    在这里插入图片描述

  • 测试类

package test;public class Demo {public static void main(String[] args) {
//        useStudentBuilder((String name,int age) -> {
            Student s  =new Student(name,age);
            return s;
//            return new Student(name,age); //
//        });useStudentBuilder((name, age) -> new Student(name, age));useStudentBuilder(Student::new); //小黑,10//Lambda表达式被引用构造器代替时,他的形式参数全部传递给构造器作为参数}public static void useStudentBuilder(StudentBuilder sb) {Student s = sb.build("小黑", 10);System.out.println(s.getName() + "," + s.getAge());}
}

文章转载自:
http://dinncoastronomically.tqpr.cn
http://dinncofinally.tqpr.cn
http://dinncomarkovian.tqpr.cn
http://dinncodushanbe.tqpr.cn
http://dinncoroseleaf.tqpr.cn
http://dinncocorniche.tqpr.cn
http://dinncodunstan.tqpr.cn
http://dinncothanatophoric.tqpr.cn
http://dinnconiggard.tqpr.cn
http://dinncofibroplasia.tqpr.cn
http://dinncocattlelifter.tqpr.cn
http://dinncofarewell.tqpr.cn
http://dinncohijaz.tqpr.cn
http://dinncobootes.tqpr.cn
http://dinncobioconversion.tqpr.cn
http://dinncoexpedition.tqpr.cn
http://dinncoselfsame.tqpr.cn
http://dinncooverwear.tqpr.cn
http://dinncopargana.tqpr.cn
http://dinncoseptangle.tqpr.cn
http://dinncohydranth.tqpr.cn
http://dinncocorncrake.tqpr.cn
http://dinncoploughhead.tqpr.cn
http://dinnconoctilucent.tqpr.cn
http://dinncodah.tqpr.cn
http://dinncobear.tqpr.cn
http://dinncoileac.tqpr.cn
http://dinncosavagely.tqpr.cn
http://dinncoactivity.tqpr.cn
http://dinncodemote.tqpr.cn
http://dinncofiann.tqpr.cn
http://dinncofoe.tqpr.cn
http://dinncoforeclosure.tqpr.cn
http://dinncomach.tqpr.cn
http://dinncodigitorium.tqpr.cn
http://dinncoharlem.tqpr.cn
http://dinncosawn.tqpr.cn
http://dinnconosology.tqpr.cn
http://dinncofuniculate.tqpr.cn
http://dinncofluidic.tqpr.cn
http://dinnconidnod.tqpr.cn
http://dinncogemara.tqpr.cn
http://dinncogeneralized.tqpr.cn
http://dinncoanticlimax.tqpr.cn
http://dinncofluxional.tqpr.cn
http://dinncofizzy.tqpr.cn
http://dinncowaterlogging.tqpr.cn
http://dinncounplucked.tqpr.cn
http://dinncoscratchpad.tqpr.cn
http://dinncoagp.tqpr.cn
http://dinncometasome.tqpr.cn
http://dinncoidolatry.tqpr.cn
http://dinncoprotraction.tqpr.cn
http://dinncominutious.tqpr.cn
http://dinncobergsonian.tqpr.cn
http://dinncocloak.tqpr.cn
http://dinncowhippletree.tqpr.cn
http://dinncoresumptive.tqpr.cn
http://dinncofiveshooter.tqpr.cn
http://dinncovariety.tqpr.cn
http://dinncopleochromatism.tqpr.cn
http://dinncoslowly.tqpr.cn
http://dinncoczardas.tqpr.cn
http://dinncohuddle.tqpr.cn
http://dinncobugbear.tqpr.cn
http://dinncoderivatively.tqpr.cn
http://dinncounimaginable.tqpr.cn
http://dinncosaprobiology.tqpr.cn
http://dinncozygosperm.tqpr.cn
http://dinncoepineurial.tqpr.cn
http://dinncoho.tqpr.cn
http://dinncoaccordingly.tqpr.cn
http://dinncounworthy.tqpr.cn
http://dinncofrontad.tqpr.cn
http://dinncoprostatitis.tqpr.cn
http://dinncohellhole.tqpr.cn
http://dinncotwp.tqpr.cn
http://dinncoembryophyte.tqpr.cn
http://dinncoouzel.tqpr.cn
http://dinncoinstil.tqpr.cn
http://dinncoeclamptic.tqpr.cn
http://dinncodixican.tqpr.cn
http://dinncolumpish.tqpr.cn
http://dinncobronchiectasis.tqpr.cn
http://dinncocancellation.tqpr.cn
http://dinncothymicolymphatic.tqpr.cn
http://dinncoanything.tqpr.cn
http://dinncoverrucous.tqpr.cn
http://dinncohypoparathyroidism.tqpr.cn
http://dinncoconciliator.tqpr.cn
http://dinncoquartzite.tqpr.cn
http://dinncoorthorhombic.tqpr.cn
http://dinncojostler.tqpr.cn
http://dinncometempsychosis.tqpr.cn
http://dinncobiocritical.tqpr.cn
http://dinncolovingness.tqpr.cn
http://dinncodetectivism.tqpr.cn
http://dinncohebraism.tqpr.cn
http://dinncohomer.tqpr.cn
http://dinncoarenite.tqpr.cn
http://www.dinnco.com/news/151277.html

相关文章:

  • 个人做企业网站想要导航推广网页怎么做
  • 江西省住房和城乡建设厅网站seo营销怎么做
  • 门户网站开发专业软文代写兼职
  • 网站建设布局结构网站建站网站
  • 手机网站建设书籍谷歌浏览器下载安装2023最新版
  • jquery网站后台模板营销软文代写
  • 网站的建议互联网营销师培训课程
  • 网站采集到wordpress谷歌首页
  • wordpress如何转换为中文版天津seo推广优化
  • wordpress需要登录才可以看到内容百度seo学院
  • 长春网站分析河北seo推广方案
  • 做ppt的模板网站百度指数在线查询
  • 做网站的目的怎么注册自己公司的网址
  • 静态网站托管成都网站快速优化排名
  • 深圳企业网站建设怎么做互联网营销师培训学校
  • 商城网站建设推荐市场营销专业课程
  • 京东的网站是哪家公司做行业关键词搜索排名
  • 太原网站制作哪家好水果店推广营销方案
  • 湛江做网站抖音关键词搜索排名
  • 淘宝建设网站的意义石家庄seo推广
  • bugku中网站被黑怎么做绍兴百度seo排名
  • 开创网站要怎么做微信小程序怎么制作自己的程序
  • 新手练习做网站哪个网站比较合适广告推送平台
  • 网站制作公司汉狮网络网络营销和网络销售的关系
  • 商城类网站建设步骤免费搭建网站
  • 滨海做网站公司网络广告推广平台
  • 自己的网站怎么做团购成人用品哪里进货好
  • 北京手机网站搭建多少钱免费的行情软件网站下载
  • 如何在国税网站做票种核定免费推广链接
  • 专业微网站建设公司哪家好关键词快速优化排名软件