发布网友 发布时间:2022-10-10 18:40
共2个回答
热心网友 时间:2023-10-09 06:21
[mw_shl_code=java,true]import java.lang.reflect.Field; public class FieldTest { public static void main(String[] args) { try { A a = new A(); Field field = a.getClass().getDeclaredField("a"); field.setAccessible(true); field.set(a, 2); System.out.println(field.get(a)); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } class A { private static final int a = 1; } [/mw_shl_code] 到eoeAndroid网站查看回答详情>>热心网友 时间:2023-10-09 06:22
final 无法修改。