File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
jvm/src/main/scala/org/portablescala/reflect Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 1
1
package org .portablescala .reflect
2
2
3
- /** A wrapper for a class that can be instantiated.
3
+ import java .lang .reflect .InvocationTargetException
4
+
5
+ /**
6
+ * A wrapper for a class that can be instantiated.
4
7
*
5
8
* @param runtimeClass
6
9
* The `java.lang.Class[_]` representing the class.
7
10
*/
8
11
final class InstantiatableClass private [reflect] (val runtimeClass : Class [_]) {
12
+
9
13
/** A list of the public constructors declared in this class. */
10
14
val declaredConstructors : List [InvokableConstructor ] =
11
- runtimeClass.getConstructors() .map(new InvokableConstructor (_)).toList
15
+ runtimeClass.getConstructors.map(new InvokableConstructor (_)).toList
12
16
13
- /** Instantiates this class using its zero-argument constructor.
17
+ /**
18
+ * Instantiates this class using its zero-argument constructor.
14
19
*
15
20
* @throws java.lang.InstantiationException
16
21
* (caused by a `NoSuchMethodException`)
17
22
* If this class does not have a public zero-argument constructor.
18
23
*/
19
24
def newInstance (): Any = {
20
25
try {
21
- runtimeClass.newInstance()
26
+ runtimeClass.getDeclaredConstructor(). newInstance()
22
27
} catch {
23
- case e : IllegalAccessException =>
28
+ case e : InvocationTargetException if e.getCause != null =>
29
+ throw e.getCause
30
+ case e : NoSuchMethodException =>
31
+ throw new InstantiationException (runtimeClass.getName).initCause(e)
32
+ case _ : IllegalAccessException =>
24
33
/* The constructor exists but is private; make it look like it does not
25
34
* exist at all.
26
35
*/
You can’t perform that action at this time.
0 commit comments