Why does Java allow type-unsafe Array assignments?

前端 未结 5 1270
孤独总比滥情好
孤独总比滥情好 2020-12-29 09:19

Generally, Java can be considered as a type-safe language. I know that there are some flaws with generics, but I recently came across a Problem I never had before. To break

5条回答
  •  失恋的感觉
    2020-12-29 10:03

    actually in case of arrays you get a exception at run time called ArrayStoreException when you add wrong type of element In this case a String. In case of generics there is no such exception. its for the very same reason you are not allowed to add anything but object, as you might just add a wrong type into the list.

提交回复
热议问题