java是歪果仁发明的,现在sun公司已经被oracle收购。原来已经好久了。
以前总以为java历史久远,其实还没有我年纪大。
我想多尝试尝试英语环境。还是多用google和facebook吧
ok。java 8 new Feature in oracle,大家一起看看老外的原文。
https://www.oracle.com/java/technologies/javase/8-whats-new.html
世界好复杂呀,我发现自己也就是单细胞生物,想的太多,做的太少,还是好好专注自己的一亩三分地。做能做该做的事情,少去关注时事政治吃瓜等让我困惑困扰痛苦的。
java programming language
Lambda expression
Lambda表达式封装一个行为单元,并且传递给其他代码。you can use a lambda expressions if you want a certain action performed om each of a collection.如果你想在集合的每个元素上拥有特定的行为,应该使用Lambda表达式。
public class LambdaTest {
public static void main(String[] args) {
Function<Integer, Integer> function = (a) -> a = a + 1;
// function = function.andThen((v) -> v *= v);
function = function.compose((v) -> v * v);
System.out.println(function.apply(3));
}
}
java为什么要引入lamdba? lambda是可以理解为一个代码块,独立的逻辑单元。将函数提高到和基本数据类型,class类型一样的高度。你想,以前变量,只有基本类型和对象引用。现在函数也可以作为变量,进行传递了。
实现是java引入了大量的函数式编程接口。
总结下命名规则:
function ------- 单参数单返回值
consumer --------- 单参数返回void
predicate --------- 单参数返回boolean
supplier ---------- 无参数返回值
Bi前缀 ----------binary的意思,代表两个参数
double int long -------- to开头代表返回值, 否则代表参数是double等
方法引用 method reference
是compact 紧凑的,easy to read lambda expressions ,用于已经有名字的方法
方法引用。相当于把对象的某个方法抽取出来,当做lambda代码块
Function<Integer, Integer> function = Hjq::cc;
class Hjq {
static int cc(int c) {
return c;
}
}
default关键字
现在可以在interface上编写method的默认实现,可以兼容老代码;只需要再method前添加default signature。此外,也能编写static方法
public class LambdaTest {
public static void main(String[] args) {
IHjq hjq = (a) -> a;
System.out.println(hjq.tt2(44));
System.out.println(hjq.tt());
System.out.println(IHjq.tt1());
}
}
class Hjq {
static int cc(int c) {
return c;
}
}
interface IHjq {
int tt2(int c);
default int tt() {
return 1;
}
static int tt1() {
return 1;
}
}
接口可以增加default方法和static方法。默认方法就是接口实现类拥有默认方法,static是类方法,接口就能调用了。
增强的类型推断 improved Type inference
java compile能利用目标类型infer推理隐识类型type parameters
the target type of an expression expects depending on where the expression appears
表达式的目标类型预测依赖于表达式的外观前置
public class LambdaTest {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
}
}
你懂得,java8根据结果泛型,推导出创建的对象泛型。
重复注解
同一个type上,可以不止once去apply an annotation
@Hjq
@Hjq
public class LambdaTest {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
}
private void fun(@Hjq int c) {
}
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.TYPE)
@interface Hjqs {
Hjq[] value();
}
@Repeatable(Hjqs.class)
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE, ElementType.PARAMETER})
@interface Hjq {
String value() default "123";
}
可重复注解,关键点在于要创建一个数组的注解,拥有存储多个相同注解。意味着至少两个注解才能实现多注解。使用场景,估计就是获取多个值吧
方法参数映射 method parameter reflection
现在compile的class文件上,可以有方法和构造函数的参数name。但这不是default action。 compile source code with the -parameters option in java compile
这要提一下。以前我们使用mybatis,传参到xml文件,需要@Param()注解,当你编译java文件,带上-parameters参数后,class文件就带上参数的name了。简化了代码。
collection集合
提供了java.util.stream api提供。
stream api 被整合进Collection api中函数式设计,functional type operator on 元素流。
operation,例如串行和并行 map-reduce操作
hashmap的key查找,性能提升。
要涉及到hashmap,concurrenthashMap的查找实现改变
compact profile 简化的profile
对于一些小型devices,不需要entire的platform. java se上有一套profile子集
Security
一大串算法名词,尴尬,都不懂。列几个名词。sha-224
enhanced support for high entropy random number generation
javaFX
javaFX之前没注意过,它是一系列类库,用于graphics和media。构建富文本client
Javac tool
the -parameters on javac command can be used to store formal parameter names and reflection api to retrieve formal parameter names.
javadoc
原来javadoc一直也在更新,看到可以traverse javadoc comments as abstract syntax trees
国家化 Internationalization
unicode enhanced,support unicode 6.2.0
new calenda api and locale apis 新的calendar和locale
ability to install a custom resource bundle as an extension
date time package that provide a comprehensie date-time model
权限的日期包,提供全面的日期模型
Nashorn JavaScript engine
java lang and java.util package
提供了 paraller array sorting
标准的encode and decoding base64
java 8 includes java db10.10
java concurrency并发
新增和修改了concurrent包下的class和interface
更新了concurrentHashMap
java.util.concurrent.atomic支持scalable updatable variable
add fork Join支持线程池
The java.util.concurrent.locks.StampedLock class has been added to provide a capability-based lock with three modes for controlling read/write access.