java如何将其添加到列表中?
final List<S> s = new ArrayList<S>();
我已经创建了3个对象,并将它们添加到列表中
A a = new("l", "m"); // creating object a
B b = new ("n", "o"); // createing b obj
C c = new("p", "q"); // creating c obj
现在我在列表中添加a
、b
、c
s.add(a); // adding to the list s
s.add(b); // adding to the list s
s.add(c); // adding to the list s
现在我必须为A、B和C添加类型
a.setType("Z"); // a, b and c have same Type
b.setType("z"); // a, b, c have same type
c.setType("z"); // a,,b , c have same type
所以,我可以只做一次,而不是做三次吗
现在a
、b
和c
具有我必须传递的相同类型。怎么做?
谁能给我提个建议吗
共 (0) 个答案