一个 Java 构造函数可以提升类型吗?

huangapple go评论65阅读模式
英文:

Can a Java constructor promote a type?

问题

如果我理解正确,Java方法可以提升类型:例如,如果方法的参数是两个int,则可以将两个byte变量传递给调用,并且它们将被提升为int。构造函数也是如此吗?如果构造函数的参数是两个int,那么是否可以将两个byte变量传递给它?

英文:

If I understand correctly, Java methods can promote types: for example, if a method's parameters are two ints, two byte variables can be passed to the invocation, and they will be promoted to ints. Is this true of constructors? Could two byte variables be passed to a constructor whose parameters are two ints?

答案1

得分: 1

可以,您可以将字节参数传递给构造函数中的整数参数。
那里发生的情况被称为扩大原始转换

英文:

Yes, you can pass byte arguments to integer parameters in constructor.
What happens there is called Widening Primitive Conversion

huangapple
  • 本文由 发表于 2020年8月18日 01:18:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63455650.html
匿名

发表评论

匿名网友

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

确定