1.6 使用Compiler API函数
JDK6 的Compiler API(JSR 199)去动态编译Java源文件,Compiler API结合反射功能就能够实现动态的产生Java代码并编译执行这些代码,有点动态语言的特征。spa
Compiler API经过一套易用的标准的API提供了更加丰富的方式去作动态编译,并且是跨平台的。code
1.7orm
1.switch中能够使用字串对象
ListtempList = new ArrayList<>(); 即泛型实例化类型自动推断。接口
interface AutoCloseable
只要实现该接口,在该类对象销毁时自动调用close方法,你能够在close方法关闭你想关闭的资源资源
List<String> list=["item"]; //向List集合中添加元素
it
String item=list[0]; //从List集合中获取元素
io
Set<String> set={"item"}; //向Set集合对象中添加元素
编译
Map<String,Integer> map={"key":1}; //向Map集合中添加对象
int value=map["key"]; //从Map集合中获取对象
int one_million = 1_000_000;
int binary = 0b1001_1001;
try {
......
} catch(ClassNotFoundException|SQLException ex) {
ex.printStackTrace();
}
public class FileCopyJDK7 {
public static void main(String[] args) {
try (BufferedReader in = new BufferedReader(new FileReader("in.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("out.txt"))) {
int charRead;
while ((charRead = in.read()) != -1) {
System.out.printf("%c ", (char)charRead);
out.write(charRead);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
1.8
interface Formula {
double calculate(int a);
default double sqrt(int a) {
return Math.sqrt(a);
}
}
.....
https://mp.weixin.qq.com/s/-mG6XsXLCXTnL-efV3mX4Q