enumtroubletoo.java
来自「JAVA 工作指南 可以说是程序员必备的东西哦」· Java 代码 · 共 26 行
JAVA
26 行
import java.lang.reflect.Field;enum E0 { A, B }enum E1 { A, B }class ETest { private E0 fld = E0.A;}public class EnumTroubleToo { public static void main(String... args) { try { ETest test = new ETest(); Field f = test.getClass().getDeclaredField("fld"); f.setAccessible(true); f.set(test, E1.A); // IllegalArgumentException // production code should handle these exceptions more gracefully } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?