1,- public class Something {
- public int addOne(final int x) {
- return ++x;
- }
- }
复制代码 2,- public class Something {
- public static void main(String[] args) {
- Other o = new Other();
- new Something().addOne(o);
- }
- public void addOne(final Other o) {
- o.i++;
- }
- }
- class Other {
- public int i;
- }
复制代码 为什么以上两题的参数同样被修饰成final,1是错的,而2就是对的呢? |