[英]java - Cannot convert Integer to int
I am stuck at this problem for ages. 我长期坚持这个问题。 Basically I cannot convert Integer to int.
基本上我不能将Integer转换为int。
class CheckOdd implements Check<Integer>
{
public <Integer> boolean check(Integer num)
{
int i = (Integer) num;
return (i % 2 != 0);
}
}
I have tried using 我试过用
int i = (Integer) object;
int i = (int) object;
intValue()
but still no luck. 但仍然没有运气。 If I use
int i = (Integer) object;
如果我使用
int i = (Integer) object;
it produce error:incompatible types
. 它产生
error:incompatible types
。 If I use int i = (int) object;
如果我使用
int i = (int) object;
it produce error: inconvertible types
. 它产生
error: inconvertible types
。
Please Help. 请帮忙。 Thank you in advance.
先感谢您。
You've replaced java.lang.Integer
with a generic type which you have named Integer
您已使用名为
Integer
的泛型类型替换了java.lang.Integer
public <Integer> boolean check(Integer num) // <-- not a java.lang.Integer
should be 应该
public boolean check(Integer num)
After java 1.5 Autoboxing was supported. 在支持java 1.5 Autoboxing之后。 So you can use
所以你可以使用
int i = num;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.