Java:自动装箱和强制转换有什么区别? [英] Java: What's the difference between autoboxing and casting?

查看:21
本文介绍了Java:自动装箱和强制转换有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于为什么自动装箱使 Java 中的一些调用变得模棱两可?"

This question is about "Why does autoboxing make some calls ambiguous in Java?"

但是仔细阅读答案,有很多关于转换的参考资料,我不确定我是否完全理解其中的区别.

But reading through the answers, there are a number of references to casting and I'm not sure I completely understand the difference.

谁能提供一个简单的解释?

Can someone provide a simple explanation?

推荐答案

装箱是将原始类型转换为引用类型,而取消装箱则相反.强制转换是当您希望将一种类型视为另一种类型时,在原始类型和引用类型之间,这意味着隐式或显式装箱操作.是否需要显式是语言特性.

Boxing is when you convert a primitive type to a reference type, un-boxing is the reverse. Casting is when you want one type to be treated as another type, between primitive types and reference types this means an implicit or explicit boxing operation. Whether it needs to be explicit is a language feature.

这篇关于Java:自动装箱和强制转换有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆