英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论