dimanche 9 juin 2019

Convert Object to Array type via class

I have to iterate an array of an unkown type.

The type internally does not really matter and it comes as an Object.

think of something like this.

Object obj = new String[]{"hi"} // can be this
Object obj = new int[]{0} // or this
Object obj = new SuperCustomComplexObject[]{...} // or even this

// arr = obj (conversion through magic)
Arrays.stream(arr).map // blah blah blah

I know how to get the class through reflection but I am not sure how to cast it to something Arrays can accept.





Aucun commentaire:

Enregistrer un commentaire