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

大英县住房和城乡建设局网站网站建设公司哪个好呀

大英县住房和城乡建设局网站,网站建设公司哪个好呀,服装企业官方网站,wordpress rss格式如果需要使用Lambda接口&#xff0c;就必须要有一个函数式接口 函数式接口是有且仅有一个抽象方法的接口, 对应的注解是FunctionalInterface Java中内置的常见函数式接口如下: 1.Runnable/ Callable /*** The <code>Runnable</code> interface should be implem…

如果需要使用Lambda接口,就必须要有一个函数式接口

函数式接口是有且仅有一个抽象方法的接口, 对应的注解是@FunctionalInterface

Java中内置的常见函数式接口如下:

1.Runnable/ Callable

/*** The <code>Runnable</code> interface should be implemented by any* class whose instances are intended to be executed by a thread. The* class must define a method of no arguments called <code>run</code>.* <p>* This interface is designed to provide a common protocol for objects that* wish to execute code while they are active. For example,* <code>Runnable</code> is implemented by class <code>Thread</code>.* Being active simply means that a thread has been started and has not* yet been stopped.* <p>* In addition, <code>Runnable</code> provides the means for a class to be* active while not subclassing <code>Thread</code>. A class that implements* <code>Runnable</code> can run without subclassing <code>Thread</code>* by instantiating a <code>Thread</code> instance and passing itself in* as the target.  In most cases, the <code>Runnable</code> interface should* be used if you are only planning to override the <code>run()</code>* method and no other <code>Thread</code> methods.* This is important because classes should not be subclassed* unless the programmer intends on modifying or enhancing the fundamental* behavior of the class.** @author  Arthur van Hoff* @see     java.lang.Thread* @see     java.util.concurrent.Callable* @since   JDK1.0*/
@FunctionalInterface
public interface Runnable {/*** When an object implementing interface <code>Runnable</code> is used* to create a thread, starting the thread causes the object's* <code>run</code> method to be called in that separately executing* thread.* <p>* The general contract of the method <code>run</code> is that it may* take any action whatsoever.** @see     java.lang.Thread#run()*/public abstract void run();
}

分别用匿名内部类和Lambda实现Runnable

public class RunnableLambda {public static void main(String[] args) {new Thread(new Runnable() {@Overridepublic void run() {String name = Thread.currentThread().getName();System.out.println(name);}}).start();new Thread(()->{String name = Thread.currentThread().getName();System.out.println(name);}).start();}
}

Callable和Runnable类似

2.Supplier

特点:无方法参数, 返回值为定义的泛型

JDK中Supplier对应的定义:

package java.util.function;/*** Represents a supplier of results.** <p>There is no requirement that a new or distinct result be returned each* time the supplier is invoked.** <p>This is a <a href="package-summary.html">functional interface</a>* whose functional method is {@link #get()}.** @param <T> the type of results supplied by this supplier** @since 1.8*/
@FunctionalInterface
public interface Supplier<T> {/*** Gets a result.** @return a result*/T get();
}

Supplier的使用

public class SupplierLambda {public static void main(String[] args) {int[] arr = {2, 5, 8, 10, 500, 500, 50000};int max = getMax(() -> {int curMax = arr[0];for(int i = 1; i < arr.length; i++) {if(arr[i] > curMax) {curMax = arr[i];}}return curMax;});System.out.println(max);}public static int getMax(Supplier<Integer> supplier) {return supplier.get();}
}

3.Consumer

特点:一个输入参数 无输出 可以对一个入参进行多次使用(使用andThen)

JDK中Consumer的定义

package java.util.function;import java.util.Objects;/*** Represents an operation that accepts a single input argument and returns no* result. Unlike most other functional interfaces, {@code Consumer} is expected* to operate via side-effects.** <p>This is a <a href="package-summary.html">functional interface</a>* whose functional method is {@link #accept(Object)}.** @param <T> the type of the input to the operation** @since 1.8*/
@FunctionalInterface
public interface Consumer<T> {/*** Performs this operation on the given argument.** @param t the input argument*/void accept(T t);/*** Returns a composed {@code Consumer} that performs, in sequence, this* operation followed by the {@code after} operation. If performing either* operation throws an exception, it is relayed to the caller of the* composed operation.  If performing this operation throws an exception,* the {@code after} operation will not be performed.** @param after the operation to perform after this operation* @return a composed {@code Consumer} that performs in sequence this* operation followed by the {@code after} operation* @throws NullPointerException if {@code after} is null*/default Consumer<T> andThen(Consumer<? super T> after) {Objects.requireNonNull(after);return (T t) -> { accept(t); after.accept(t); };}
}

Consumer的使用

import java.util.function.Consumer;public class ConsumerLambda {public static void main(String[] args) {consumerString(s-> System.out.println(s.toUpperCase()),s-> System.out.println(s.toLowerCase()));}static void consumerString(Consumer<String> comsumer) {comsumer.accept("Hello");}static void consumerString(Consumer<String> firstConsumer, Consumer<String> secondConsumer) {firstConsumer.andThen(secondConsumer).accept("Hello");}
}

4.Comparator

特点:两个参数(类型根据指定的泛型),返回值为int

JDK中关于Comparator的定义太长有500多行,我这里就不贴了,自己去看吧

使用如下:

import java.util.Arrays;
import java.util.Comparator;public class ComparatorLambda {public static void main(String[] args) {String[] strs = {"delay","a", "ab", "abc", "bcd"};Comparator<String> comparator = new Comparator<String>() {@Overridepublic int compare(String o1, String o2) {return o1.length() - o2.length();}};Arrays.sort(strs, comparator);System.out.println(Arrays.toString(strs));Arrays.sort(strs, (o1, o2)-> o2.length() - o1.length());System.out.println(Arrays.toString(strs));}
}

5.Predicate

特点:一个入参(类型由泛型指定),出参为boolean,内含条件判断方法,常用于判断

JDK中的定义如下:

package java.util.function;import java.util.Objects;/*** Represents a predicate (boolean-valued function) of one argument.** <p>This is a <a href="package-summary.html">functional interface</a>* whose functional method is {@link #test(Object)}.** @param <T> the type of the input to the predicate** @since 1.8*/
@FunctionalInterface
public interface Predicate<T> {/*** Evaluates this predicate on the given argument.** @param t the input argument* @return {@code true} if the input argument matches the predicate,* otherwise {@code false}*/boolean test(T t);/*** Returns a composed predicate that represents a short-circuiting logical* AND of this predicate and another.  When evaluating the composed* predicate, if this predicate is {@code false}, then the {@code other}* predicate is not evaluated.** <p>Any exceptions thrown during evaluation of either predicate are relayed* to the caller; if evaluation of this predicate throws an exception, the* {@code other} predicate will not be evaluated.** @param other a predicate that will be logically-ANDed with this*              predicate* @return a composed predicate that represents the short-circuiting logical* AND of this predicate and the {@code other} predicate* @throws NullPointerException if other is null*/default Predicate<T> and(Predicate<? super T> other) {Objects.requireNonNull(other);return (t) -> test(t) && other.test(t);}/*** Returns a predicate that represents the logical negation of this* predicate.** @return a predicate that represents the logical negation of this* predicate*/default Predicate<T> negate() {return (t) -> !test(t);}/*** Returns a composed predicate that represents a short-circuiting logical* OR of this predicate and another.  When evaluating the composed* predicate, if this predicate is {@code true}, then the {@code other}* predicate is not evaluated.** <p>Any exceptions thrown during evaluation of either predicate are relayed* to the caller; if evaluation of this predicate throws an exception, the* {@code other} predicate will not be evaluated.** @param other a predicate that will be logically-ORed with this*              predicate* @return a composed predicate that represents the short-circuiting logical* OR of this predicate and the {@code other} predicate* @throws NullPointerException if other is null*/default Predicate<T> or(Predicate<? super T> other) {Objects.requireNonNull(other);return (t) -> test(t) || other.test(t);}/*** Returns a predicate that tests if two arguments are equal according* to {@link Objects#equals(Object, Object)}.** @param <T> the type of arguments to the predicate* @param targetRef the object reference with which to compare for equality,*               which may be {@code null}* @return a predicate that tests if two arguments are equal according* to {@link Objects#equals(Object, Object)}*/static <T> Predicate<T> isEqual(Object targetRef) {return (null == targetRef)? Objects::isNull: object -> targetRef.equals(object);}
}

简单用法

import java.util.function.Predicate;public class PredicateLambda {public static void main(String[] args) {andMethod(s->s.contains("W"),s-> s.contains("H"));orMethod(s->s.contains("W"),s-> s.contains("H"));negateMethod(s->s.length()>5);}static void andMethod(Predicate<String> first, Predicate<String> second) {boolean isValid = first.and(second).test("helloWorld");System.out.println("字符串符合要求吗:" + isValid);}static void orMethod(Predicate<String> first, Predicate<String> second) {boolean isValid = first.or(second).test("helloWorld");System.out.println("字符串符合要求吗:" + isValid);}static void negateMethod(Predicate<String> predicate) {boolean tooLong = predicate.negate().test("helloWorld");System.out.println("字符串特别长吗:" + tooLong);}

6.Function

特点:一个入参,有出参,入参和出参的类型都由泛型指定,可以多次处理(从第一个开始处理,然后把返回值作为第二个、第三个。。。的结果)

它的实例应该是具备某种功能的  

简单使用如下:

import java.util.function.Function;public class FunctionLambda {public static void main(String[] args) {method(str-> Integer.parseInt(str) + 10,strInt -> strInt *= 10);String str = "zhangsan,80";int age = getAgeNum(str,s->s.split(",")[1],s->Integer.parseInt(s),i-> i -= 10);System.out.println("zhangsan十年前的年龄是:" + age);}static void method(Function<String, Integer> first, Function<Integer, Integer> second) {int num = first.andThen(second).apply("10");System.out.println(num);}static int getAgeNum(String str, Function<String, String> first,Function<String, Integer> second,Function<Integer, Integer> third) {return first.andThen(second).andThen(third).apply(str);}
}


文章转载自:
http://ensheath.wwxg.cn
http://propitiatory.wwxg.cn
http://usable.wwxg.cn
http://forcer.wwxg.cn
http://sargassumfish.wwxg.cn
http://evolvement.wwxg.cn
http://uh.wwxg.cn
http://andromonoecious.wwxg.cn
http://purveyor.wwxg.cn
http://subquadrate.wwxg.cn
http://stagnate.wwxg.cn
http://volvulus.wwxg.cn
http://decathlon.wwxg.cn
http://gobbledegook.wwxg.cn
http://carefree.wwxg.cn
http://workaround.wwxg.cn
http://rdac.wwxg.cn
http://response.wwxg.cn
http://polymerise.wwxg.cn
http://orthoptist.wwxg.cn
http://turion.wwxg.cn
http://despair.wwxg.cn
http://tramontane.wwxg.cn
http://vesiculous.wwxg.cn
http://wapenshaw.wwxg.cn
http://plastral.wwxg.cn
http://headfast.wwxg.cn
http://parotic.wwxg.cn
http://prealtar.wwxg.cn
http://pledger.wwxg.cn
http://bobber.wwxg.cn
http://brazenly.wwxg.cn
http://augustan.wwxg.cn
http://heidelberg.wwxg.cn
http://coacervation.wwxg.cn
http://usquebaugh.wwxg.cn
http://catharine.wwxg.cn
http://woolgrower.wwxg.cn
http://aphides.wwxg.cn
http://antigenicity.wwxg.cn
http://misdata.wwxg.cn
http://boring.wwxg.cn
http://filiation.wwxg.cn
http://irreclaimable.wwxg.cn
http://countercurrent.wwxg.cn
http://nudey.wwxg.cn
http://backdown.wwxg.cn
http://symbolization.wwxg.cn
http://exceedingly.wwxg.cn
http://headachy.wwxg.cn
http://thinnet.wwxg.cn
http://maricon.wwxg.cn
http://bernadette.wwxg.cn
http://countercoup.wwxg.cn
http://endpaper.wwxg.cn
http://vesuvian.wwxg.cn
http://pupillary.wwxg.cn
http://swordsmanship.wwxg.cn
http://chlorinity.wwxg.cn
http://inexpertise.wwxg.cn
http://whitleyism.wwxg.cn
http://test.wwxg.cn
http://capitation.wwxg.cn
http://thickback.wwxg.cn
http://aerocraft.wwxg.cn
http://builder.wwxg.cn
http://brewage.wwxg.cn
http://anticonvulsant.wwxg.cn
http://campeche.wwxg.cn
http://abradant.wwxg.cn
http://innkeeper.wwxg.cn
http://clout.wwxg.cn
http://scathing.wwxg.cn
http://danforth.wwxg.cn
http://fineable.wwxg.cn
http://lazyitis.wwxg.cn
http://advertizing.wwxg.cn
http://karachai.wwxg.cn
http://yeanling.wwxg.cn
http://blunderbuss.wwxg.cn
http://snowbank.wwxg.cn
http://landlocked.wwxg.cn
http://boatswain.wwxg.cn
http://axunge.wwxg.cn
http://prodigiouss.wwxg.cn
http://experimentative.wwxg.cn
http://aerotransport.wwxg.cn
http://viscerotonia.wwxg.cn
http://sargodha.wwxg.cn
http://peddlery.wwxg.cn
http://shred.wwxg.cn
http://omicron.wwxg.cn
http://somatotroph.wwxg.cn
http://montonero.wwxg.cn
http://boatable.wwxg.cn
http://preen.wwxg.cn
http://salivation.wwxg.cn
http://serenade.wwxg.cn
http://instrumentalism.wwxg.cn
http://tanu.wwxg.cn
http://www.hrbkazy.com/news/86400.html

相关文章:

  • 如何做网站架构淘宝推广平台
  • 成都网站建设费用新东方小吃培训价格表
  • 做搬家网站推广在那好网址收录
  • 建站技巧seo做得比较好的公司
  • 3733手游网站在哪里做的图片seo优化是什么意思
  • wordpress英文版切换中文版西安seo优化公司
  • 深圳画册设计策划优化seo厂家
  • 网站设计尺寸1920专业培训机构
  • 广州品牌网站建设百度小说app
  • 上海亿网站建设seo短视频加密路线
  • 织梦网站免费模板软文模板300字
  • wdcp备份网站百度推广运营公司
  • 站长之家短链接生成免费b2b网站大全免费
  • 网站建设南昌关键词搜索引擎优化推广
  • 网页设计与网站制作网站推广常用的方法
  • 网站必须做ipv6上海网站建设公司排名
  • b2b网站权重百度品牌专区怎么收费
  • 做外贸网站企业新乡网站推广
  • wordpress5.2火车头发布seo技巧优化
  • 成都网站建设吧高权重网站出售
  • centos7怎么做网站服务器自动外链工具
  • 手机模板网站生成制作软件百度软件市场
  • 怎么建网站做代理广告投放平台
  • 外贸网站建设公司流程semi final
  • 开发区网站制作公司宁德市房价
  • 中国制造网外贸平台多少钱深圳专门做seo的公司
  • 手机网站竞价网络舆情应急预案
  • 做自己的网站需要会编程吗国内网络推广渠道
  • 做坑人网站二维码软文兼职
  • 电脑如何做ppt模板下载网站品牌线上推广方式