Java泛型instanceof用法

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class C {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Map> map = new HashMap>();
		List aList = new ArrayList();
		aList.add(new A());
		aList.add(new A());
		
		map.put("1", aList);
		
		List bList = new ArrayList();
		bList.add(new B());
		bList.add(new B());
		
		map.put("2", bList);
		
		for (String s : map.keySet()) {
			List list = map.get(s);
			
			for (Object object : list) {
				if(object instanceof A) {
					System.out.println("AAA");
				} else {
					System.err.println("BBB");
				}
			}
		}
	}

} 
  

你可能感兴趣的:(Java基础,java,object,string,list,import,class)