Java generics and Array's

前端 未结 5 1455
长发绾君心
长发绾君心 2020-12-22 08:34

The following snippet makes sense yet when I run this against my unit test.. I get a ClassCastException (Object can\'t be cast to String) on the line marked with \'>>>>\'.

5条回答
  •  旧巷少年郎
    2020-12-22 09:16

    I don't know what is this code for, but it puts burden to the garbage collector, since to add one element, you allocate a new array. You should use any implementation of List for this, for example, ArrayList.

提交回复
热议问题