Converting a List to a List (or any class that extends Number)

后端 未结 4 1391
梦如初夏
梦如初夏 2021-01-02 07:34

I want to create a very generic utility method to take any Collection and convert it into a Collection of a user selectable class that extends from Number (Long, Double, Flo

4条回答
  •  被撕碎了的回忆
    2021-01-02 08:11

    Looks good to me.

    Since you have the Class token, why not avoid the unchecked cast and thus suppress warnings?

    retVal = clazz.cast(Double.valueOf(from)); 
    

提交回复
热议问题