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

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

问题描述

这个问题是关于为什么autoboxing使一些调用在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天全站免登陆