public class Test { public static void t(final O o) { //o = new O(); //ERROR o.x++; //final修饰的是实例,不会影响对o的成员的修改 } public static void t(final int i) { i++; //ERROR } public static void main(String[] args) { Test.t(new O()); } } class O { int x=0; }
很久没扣这些细节了,都忘记了。谨记之。
Powered by: 博客园 Copyright © 2025 阳光VIP Powered by .NET 9.0 on Kubernetes