1. 範型通配符中,當使用如List<? extends Basic>這種方式做爲範型參數時,表示不知道具體持有什麼類型,因此在使用java
List<? extends Map> a = new ArrayList<HashMap>(); //compile error //a.add(new HashMap<String, String>());
這種執行添加元素會編譯錯誤,可是能夠執行get操做, 覺得get時已經編譯器已經認爲存放的數據是基於Basic類型的,可是添加時不知道具體添加的會是什麼類型,認爲是不安全的因此不能添加。而List <? super T>用於方法參數中,這樣表示是一個具體的參數類型,認爲添加的參數類型只要是繼承自T的就能夠,編譯器認爲add是安全的。安全
2.transient序列化關鍵字this
import com.sun.tools.corba.se.idl.StringGen; import java.io.*; import java.lang.ref.*; import java.util.*; public class NesttyMain implements Serializable{ private Date date = new Date(); private String userName; private transient String password; public NesttyMain(String userName,String password){ this.userName = userName; this.password = password; } public String toString(){ return "username: "+userName+" \n password: "+password + "\n date: "+ date; } public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { NesttyMain a = new NesttyMain("cqq","123"); System.out.println("a = "+a); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("nestty.out")); out.writeObject(a); out.close(); Thread.sleep(1000); ObjectInputStream in = new ObjectInputStream(new FileInputStream("nestty.out")); a = (NesttyMain) in.readObject(); System.out.println("a = "+a); } }
輸出:code
執行序列化以後再讀取,transient修飾的密碼字段不會打印出來繼承