package com.zhao.test;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Test {
//@1
private Map initData = new HashMap() {
{
put("foo", "blah");
put("bar", "blah");
}
};
public static void main(String[] args) {
Test t = new Test();
System.out.println(t.initData.get("foo"));
//@2
Map init = new Map()
{
@Override
public void clear() {
// TODO Auto-generated method stub
}
@Override
public boolean containsKey(Object key) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsValue(Object value) {
// TODO Auto-generated method stub
return false;
}
@Override
public Set entrySet() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object get(Object key) {
// TODO Auto-generated method stub
return 1;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public Set keySet() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object put(Object key, Object value) {
// TODO Auto-generated method stub
return null;
}
@Override
public void putAll(Map m) {
// TODO Auto-generated method stub
}
@Override
public Object remove(Object key) {
// TODO Auto-generated method stub
return null;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Collection values() {
// TODO Auto-generated method stub
return null;
}
};
System.out.println(init.get(1));
//@3
Map init2 = new HashMap()
{
public Object get(Object key) {
// TODO Auto-generated method stub
return 6;
}
};
System.out.println(init2.get(4));
}
}
晕,上面的代码,好像不太相关
[url]http://flowercat.iteye.com/blog/33371[/url]