cc's blog

Categories · code

Home

About

Archives

java

函数式接口学习

函数式接口:实际上感觉基本体现在参数的配置上 Function:<T,R> 参数很正常,参数->结果 R apply(T t) 相当于方法的调用 compose(Function before) 先调用before再调用本身 andThen(Function after) 与上面的相反 Predict:<T, boolean> 返回为boolean boolean test(T t) 相当于方法的调用 and(Predict) 与 or(Predict) 或 negate 取反 Supplier: 没有参数传入,直接返回一个结果,相当于new的感觉 get() 方法的调用 Consumer: 没有参数返回,直接消费参数 accept(T t) 方法的基..

Read more
java

反射

创建实例。 反射通过: Class<?> c = String.class; Object str = c.newInstance(); 与new的区别: new:强类型。相对高效。能调用任何public构造。 newInstance: 弱类型。低效率。只能调用无参构造,是实现IOC、反射、面对接口编程 和 依赖倒置 等技术方法的必然选择,new 只能实现具体类的实例化,不适合于接口编程。 正因为newInstance只能调用无参构造,所以Constructor对象就十分有必要了: Class<?> c = String.class; Constructor constructor = c.getConstrutor(String.class); Object o = con..

Read more