MCPcopy Create free account
hub / github.com/java-native-access/jna / newInstance

Method newInstance

src/com/sun/jna/Klass.java:46–62  ·  view source on GitHub ↗

Create a new instance for the given klass. Runtime exceptions thrown from the constructor are rethrown, all other exceptions generated from the reflective call are wrapped into a java.lang.IllegalArgumentException and rethrown. @param klass desired class to instantiate @return the n

(Class<T> klass)

Source from the content-addressed store, hash-verified

44 * a runtime exception
45 */
46 public static <T> T newInstance(Class<T> klass) {
47 try {
48 return klass.getDeclaredConstructor().newInstance();
49 } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException e) {
50 String msg = "Can't create an instance of " + klass
51 + ", requires a public no-arg constructor: " + e;
52 throw new IllegalArgumentException(msg, e);
53 } catch (InvocationTargetException e) {
54 if (e.getCause() instanceof RuntimeException) {
55 throw (RuntimeException) e.getCause();
56 } else {
57 String msg = "Can't create an instance of " + klass
58 + ", requires a public no-arg constructor: " + e;
59 throw new IllegalArgumentException(msg, e);
60 }
61 }
62 }
63}

Callers 12

newInstanceMethod · 0.95
defaultValueMethod · 0.95
fromNativeMethod · 0.95
fromNativeMethod · 0.95
toPrimitiveArrayMethod · 0.45
toVariantMethod · 0.45
testBoundsCheckArrayMethod · 0.45
runTestCaseTestMethod · 0.45
getCallingClassMethod · 0.45
getMethodHandleMethod · 0.45

Calls

no outgoing calls

Tested by 4

testBoundsCheckArrayMethod · 0.36
runTestCaseTestMethod · 0.36