如何创建包含不可变对象的可变数组列表,Java
How to create a mutable array list containing immutable objects, Java
我有代表 table 中的列的对象,我想将其声明为最终的。其中一些列代表我的 table 中的主键,对于这些列,我想将它们添加到传递给函数的数组列表中。
如何声明一个包含 immutable 对象(列对象本身)的 mutable 列表(我可以向其中添加主键列)?
public final class Column {
private final Integer a;
private final String b;
public Column(Integer a, String b) {
this.a = a;
this.b = b;
}
public Integer getA() {
return a;
}
public String getB() {
return b;
}
}
以这种方式创建列 class,然后将对象添加到 ArrayList。
检查一下:http://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
我有代表 table 中的列的对象,我想将其声明为最终的。其中一些列代表我的 table 中的主键,对于这些列,我想将它们添加到传递给函数的数组列表中。
如何声明一个包含 immutable 对象(列对象本身)的 mutable 列表(我可以向其中添加主键列)?
public final class Column {
private final Integer a;
private final String b;
public Column(Integer a, String b) {
this.a = a;
this.b = b;
}
public Integer getA() {
return a;
}
public String getB() {
return b;
}
}
以这种方式创建列 class,然后将对象添加到 ArrayList。 检查一下:http://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html