1.final修饰对象: 对象的属性可以被改变,但是引用不能被修改
【程序一】
public class Something {
public int add(final int x) {
return ++x; }}
这是明显不正确的:int x被修饰成final,意味着x不能在add方法中被修改。
【程序二】
public class Some{
public static void main(String[] args) {
Other o = new Other();
new Some().addOne(o); }
public void addOne(final Other o) {
o.i++; }
}//这个没问题的,但是如果是:o = new Other(),就错了!*即不能改变o的地址。但是可以改变o所指向对象的属性。
2.静态内部类
又名嵌套类。其无法访问外部类非static的属性和方法。创建时无需指明外部对象。
3.try—catch新特性
try
(FileOutputStream fos =
new
FileOutputStream(file);
DataOutputStream dos =
new
DataOutputStream(fos);) {
dos.writeInt(x);
dos.writeInt(y);
}
catch
(Exception e) {
e.printStackTrace();
}
—try()括号内放入创建的资源对象,要求实现Closeable接口,如io流,socket等.
当try块结束后,直接调用资源的close()方法。无需在finally写。