dimanche 28 mars 2021

Creating array class in java [duplicate]

I am looking for a function that takes a type and returns a class representing arrays of objects of that type. For instance, if we name the function "getArrayClass", the following should be true:

getArrayClass(String.class) == String[].class == class [Ljava.lang.String

How can I create a function that does this, or does one already exist?

The following function would return a Type representing the appropriate array, but what I really need is a Class.

Type getArrayType(Type componentType) {
    return new GenericArrayType() {
        public Type getGenericComponentType() {
            return componentType;
        }
    };
}




Aucun commentaire:

Enregistrer un commentaire