Iterate enum values using java generics

前端 未结 10 1015
余生分开走
余生分开走 2020-12-02 10:55

I\'m trying to find a way to iterate through an enum\'s values while using generics. Not sure how to do this or if it is possible.

The following code illustrates

10条回答
  •  再見小時候
    2020-12-02 11:31

    The root problem is that you need to convert an array to a list, right? You can do this, by using a specific type (TimePeriod instead of T), and the following code.

    So use something like this:

    List list = new ArrayList();
    list.addAll(Arrays.asList(sizes));
    

    Now you can pass list into any method that wants a list.

提交回复
热议问题