高手来看一下 关于一个final的问题

JAVAkuroro JAVAkuroro 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这个程序中CountInt类的中的b是final类型的为什么可以赋值一个可变的数。
import java.util.ArrayList;
import java.util.List;


public class FinalTest
{
public static void main(String[] args)
{
FilledList<CoutInt> foo = new FilledList<CoutInt>(CoutInt.class);
System.out.println(foo.create(14));
}
}
class CoutInt
{
private static int a;
private final int b = a++;
@Override
public String toString()
{
return Integer.toString(b);
}

}
class FilledList<T>
{
private Class<T> classtype;
public FilledList(Class<T> type)
{
this.classtype = type;
}
public List<T> create(int Elements)
{
List<T> result = new ArrayList<T>();
try{
for(int i=0;i<Elements;i++)
{
result.add(classtype.newInstance());
}
}catch(Exception ex)
{
throw new RuntimeException();
}
return result;
}


}
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
JAVAkuroro
Java SE 62,620 成员 307,251 内容