From f3c904a0ee7268de1ceb71fcbd973ae641d7e6e8 Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Thu, 13 Oct 2022 10:37:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=87=E6=97=B6=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sjhy/plugin/factory/AbstractItemFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sjhy/plugin/factory/AbstractItemFactory.java b/src/main/java/com/sjhy/plugin/factory/AbstractItemFactory.java index b3acc8d..003e518 100644 --- a/src/main/java/com/sjhy/plugin/factory/AbstractItemFactory.java +++ b/src/main/java/com/sjhy/plugin/factory/AbstractItemFactory.java @@ -2,6 +2,8 @@ package com.sjhy.plugin.factory; import com.sjhy.plugin.entity.AbstractItem; +import java.lang.reflect.InvocationTargetException; + /** * 抽象的项目工厂 * @@ -13,9 +15,9 @@ public class AbstractItemFactory { public static > T createDefaultVal(Class cls) { try { - T instance = cls.newInstance(); + T instance = cls.getDeclaredConstructor().newInstance(); return instance.defaultVal(); - } catch (InstantiationException | IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalArgumentException("构建示例失败", e); } }