函数调用所需的类型转换将short数据类型变量作为参数 [英] type casting required on function calls taking short datatype variable as a parameter

查看:207
本文介绍了函数调用所需的类型转换将short数据类型变量作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用byte或short数据类型作为方法参数时,在方法调用上,我需要显式地转换我传递给这些方法的值。

Whenever I use byte or short data type as a method parameter, on method calls, I am required to explicitly cast the values I pass to those methods.

为了更好地解释:

void foo(short x)
{}



void main() {foo((short)32);}

如果我在这里不使用short,则会生成警告。

method foo in class px cannot be applied to given types
required: byte
found: int

我怎样才能让它变得更好?

How can I get it better?

推荐答案

没有出路。

Java没有办法代码 byte short 文字。任何数字文字都是 int 值,并且在没有强制转换的情况下将int转换为short会产生警告。

Java doesn't have a way to code byte or short literals. Any number literal is an int value and converting an int to a short without casting always creates a warning.

这篇关于函数调用所需的类型转换将short数据类型变量作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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