diff options
author | Sven Gothel <[email protected]> | 2011-03-19 08:28:38 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-03-19 08:28:38 +0100 |
commit | 684b4342d96fb16255928132c6c886a446f36f0a (patch) | |
tree | 4ffc202f84751cdf24e798f63308f78fc40df3db /src/java | |
parent | 2557207469fe581cbc9d51861953cdc88f1e9715 (diff) |
ReflectionUtil: split up createInstance() / use var-args where possible w/o change
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/jogamp/common/util/ReflectionUtil.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java index 80c892c..7617d53 100644 --- a/src/java/com/jogamp/common/util/ReflectionUtil.java +++ b/src/java/com/jogamp/common/util/ReflectionUtil.java @@ -105,7 +105,7 @@ public final class ReflectionUtil { /** * @throws JogampRuntimeException if the constructor can not be delivered. */ - public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) + public static final Constructor getConstructor(Class clazz, Class ... cstrArgTypes) throws JogampRuntimeException { try { if(null == cstrArgTypes) { @@ -125,11 +125,11 @@ public final class ReflectionUtil { /** * @throws JogampRuntimeException if the instance can not be created. */ - public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) + public static final Object createInstance(Constructor cstr, Object ... cstrArgs) throws JogampRuntimeException, RuntimeException { try { - return getConstructor(clazz, cstrArgTypes).newInstance(cstrArgs); + return cstr.newInstance(cstrArgs); } catch (Exception e) { Throwable t = e; if (t instanceof InvocationTargetException) { @@ -141,11 +141,20 @@ public final class ReflectionUtil { if (t instanceof RuntimeException) { throw (RuntimeException) t; } - throw new JogampRuntimeException("can not create instance of "+clazz, t); + throw new JogampRuntimeException("can not create instance of "+cstr.getName(), t); } } + + /** + * @throws JogampRuntimeException if the instance can not be created. + */ + public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object ... cstrArgs) + throws JogampRuntimeException, RuntimeException + { + return createInstance(getConstructor(clazz, cstrArgTypes), cstrArgs); + } - public static final Object createInstance(Class clazz, Object[] cstrArgs) + public static final Object createInstance(Class clazz, Object ... cstrArgs) throws JogampRuntimeException, RuntimeException { Class[] cstrArgTypes = null; @@ -228,7 +237,7 @@ public final class ReflectionUtil { /** * @throws JogampRuntimeException if the Method can not be found. */ - public static final Method getMethod(Class clazz, String methodName, Class[] argTypes) + public static final Method getMethod(Class clazz, String methodName, Class ... argTypes) throws JogampRuntimeException, RuntimeException { try { @@ -259,7 +268,7 @@ public final class ReflectionUtil { * @throws JogampRuntimeException if call fails * @throws RuntimeException if call fails */ - public static final Object callMethod(Object instance, Method method, Object[] args) + public static final Object callMethod(Object instance, Method method, Object ... args) throws JogampRuntimeException, RuntimeException { try { |