Creating an Array of unknown type

前端 未结 3 1054
北恋
北恋 2021-01-05 15:33

I have an object which I must validate values off the problem, some of the attributes of the Objects are arrays of custom objects. Such that it will involve some boring down

3条回答
  •  温柔的废话
    2021-01-05 16:13

    If you want to have arrays of unknown types, use generics:

     public  T[] getAttribArray(Class repeatingGrpClass)
     {
        //get the attribute based on the class (which you might get based on the enum for example)
        return (T[]) getAttrib( repeatingGrpClass.getName() ); //note that you might want to use the class object instead of its name here
     }
    

提交回复
热议问题