Java 7的主要变化
Devoxx 大会结束在几天前结束了,一位与会者对此次大会的重要内容进行了总结,他提到Java 7的主要变化如下:
1.对collections的支持
Java代码
List<String> list = new ArrayList<String>();
list.add("item");
String item = list.get(0);
Set<String> set = new HashSet<String>();
set.add("item");
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key", 1);
int value = map.get("key");
现在你还可以:
Java代码
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
2.自动资源管理
Java代码
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
becomes:
Java代码
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
You can declare more than one resource to close:
try (
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest))
{
// code
}
3.对通用实例创建(diamond)的type引用进行了改进
Java代码
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
becomes:
Java代码
Map<String, List<String>> anagrams = new HashMap<>();
4.数值可加下划线
Java代码
int one_million = 1_000_000;&n
相关文档:
一、同步问题提出
线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏。
例如:两个线程ThreadA、ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据。
public
class
Foo {
private
int
x = 100;
public
int
get ......
Static Factory Methods
Four Advantages:
1) have names
2) not required to create a new object each time they are invoked
3) return an object of any subtype of their return type
4) reduce the verbosity of creating parameterized type instances.(for example: newInstance() method) ......
一 相对路径的获得
说明:相对路径(即不写明时候到底相对谁)均可通过以下方式获得(不论是一般的java项目还是web项目)
String relativelyPath=System.getProperty("user.dir");
上述相对路径中,java项目中的 ......
UC浏览器是UC 优视科技开发的一款手机浏览器,支持WEB、WAP页面浏览,速度快而稳定,页面排版美观;具有网站导航、搜索、下载、个人数据管理等功能,您能随时随地通过UC浏览器进行无线冲浪,将互联网装进口袋,享受高质移动生活!
今天,UC浏览器7.0 正式版终于和大家见面了,新版 ......