Java generics and Array's

前端 未结 5 1457
长发绾君心
长发绾君心 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:22

    You should not create your array using new Object[]. You should use Array.newInstance(Class clazz, int length) instead.

提交回复
热议问题