Autoboxing/Unboxing while casting Integer to int using 'cast' method

大憨熊 提交于 2019-12-02 02:04:18

cast can't really work well for primitives, given that it can't return a value of the actual primitive type, due to generics in Java... so it would end up boxing again anyway. And if you're not assigning straight to an int value, it would have to be boxed for that reason too.

So basically, if you want to convert to int, just cast directly.

isInstance is documented to always return false for primitives:

If this Class object represents a primitive type, this method returns false.

... cast probably should be too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!