Consider adding new reflection utility to instantiate a generic array #978
Closed
sleberknight
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
I have added |
Beta Was this translation helpful? Give feedback.
1 reply
-
I am marking this discussed as Closed since it is now in kiwi-beta and may be moved to kiwi at some point. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just came across a situation where we needed to create a new empty array with a generic type
T
. If Java allowed this, it might look like:But we could add a helper method to
KiwiReflection
to accomplish this usingArray.newInstance
for example:And we could also add one to create an empty generic array of a specific length:
And then we could also have another
newArray
that uses varargs (since there is aArray.newInstance(Class<?> componentType, int... dimensions)
to create a multidimensional generic array. But starting with just the first one or two is probably good enough, especially since the only actual need was for an empty generic array.Beta Was this translation helpful? Give feedback.
All reactions