标签:runnable star gen general java8新特性 exce creat 返回值 code
@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(); }
@FunctionalInterface public interface Comparator<T> { /** * * @param o1 the first object to be compared. * @param o2 the second object to be compared. * @return a negative integer, zero, or a positive integer as the * first argument is less than, equal to, or greater than the * second. * @throws NullPointerException if an argument is null and this * comparator does not permit null arguments * @throws ClassCastException if the arguments‘ types prevent them from * being compared by this comparator. */ int compare(T o1, T o2);
@FunctionalInterface
public interface MyNumber<T> {
public boolean compare(Integer a,Integer b); }
@Test public void test2(){ MyNumber<Integer> myNumber = (Integer a,Integer b) -> a>b; System.out.println(myNumber.compare(1,2)); }
@Test public void test() { System.out.println(studytime(()->"studyTime")); } //供给型函数,无参有返回值 public String studytime(Supplier<String> supplier){ return supplier.get(); }
@Test public void test2(){ String goodOneDay = goodDay("goodOneDay", (s -> s)); System.out.println(goodOneDay); } public String goodDay(String s, Function<String,String> function){ return function.apply(s); }
@Test public void test3(){ List<String> list = Arrays.asList("杏鲍菇","金针菇","大枣","平菇"); List<String> filterList = new ArrayList<>(); list.forEach((s)-> { if(s.contains("菇")) { filterList.add(s); } }); System.out.println("filterList:"+filterList); }
标签:runnable star gen general java8新特性 exce creat 返回值 code
原文地址:https://www.cnblogs.com/minmin123/p/12877001.html