如何在Java中决定重载方法的类型

huangapple 未分类评论47阅读模式
英文:

How do overloading methods decide on types in Java

问题

为什么这将 100 视为整型?而不是字节或短整型?

System.out.print(100);

我在某处读到这样的解释:

> 编译器会选择按照隐式转换的顺序,使用与参数类型最接近的方法。

我不明白这里所说的「最接近」是什么意思。这与内存占用或者其他什么有关吗?

英文:

Why does this treat 100 as an int? Why not as a byte or short?

System.out.print(100);

I read this somewhere:

> The compiler chooses the method that has the closest type of the argument in order of the implicit casting.

I don't understand what it means by "closest". Is it to do with the memory it takes in RAM or something?

huangapple
  • 本文由 发表于 2020年5月29日 10:39:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/62077805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定