Skip to content

Commit

Permalink
fix access to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Apr 3, 2022
1 parent ac1d23c commit 81fe1e0
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jme3.util.struct.fields;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;

import com.jme3.util.struct.Struct;
import com.jme3.util.struct.StructField;
Expand All @@ -20,7 +21,9 @@ public SubStructArrayField(int position, String name, int length, Class<? extend
private void initializeToZero(Class<? extends T> structClass) {
for (int i = 0; i < value.length; i++) {
if (value[i] == null) try {
value[i] = structClass.getDeclaredConstructor().newInstance();
Constructor<? extends T> constructor = structClass.getDeclaredConstructor();
constructor.setAccessible(true);
value[i] = constructor.newInstance();
} catch (Exception e) {
throw new RuntimeException("Can't create new instance of " + structClass + " default constructor is missing? ",e);
}
Expand Down

0 comments on commit 81fe1e0

Please sign in to comment.