From bd7d42b5166ea8bfa01a77d43a75753f7e28fad3 Mon Sep 17 00:00:00 2001 From: peierlong Date: Thu, 6 Sep 2018 18:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notes/设计模式.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/notes/设计模式.md b/notes/设计模式.md index b893599c..febb434a 100644 --- a/notes/设计模式.md +++ b/notes/设计模式.md @@ -211,14 +211,13 @@ public enum EnumSingleton { // 反射获取实例测试 try { - Constructor constructor = EnumSingleton.class.getDeclaredConstructor(); - constructor.setAccessible(true); - EnumSingleton enumSingleton = constructor.newInstance(); - System.out.println(enumSingleton.getObjName()); + EnumSingleton[] enumConstants = EnumSingleton.class.getEnumConstants(); + for (EnumSingleton enumConstant : enumConstants) { + System.out.println(enumConstant.getObjName()); + } } catch (Exception e) { e.printStackTrace(); } - } }