我的程序包含一个对象,我想了解一个包含对象的集合如何帮助我,如果我不能使用这些方法?集合与对象的反应如何?
我的代码,我用:
ClassMain c = new ClassMain();
Map<String, ClassMain> s = new HashMap<>();
s.put("S", c);
Iterator it = s.keySet().iterator();
while(it.hasNext())
{
Object key = it.next();
System.out.println(key);
}
ClassMain:
public static void main(String[] args) {
}
public void print(){
System.out.println("Printing");
}
您需要使用泛型。 – SLaks
“如果我不能使用这些方法”??什么是问题? – 2014-03-05 20:49:17
这不是问题。 – ninnemannk