javaint转object_在java上将int转换为Object 我有⼀个问题:我在
Eclipse的环境中⼯作.
有时计算机不会给出以下转换:
int a ...
Object ans = (int) a;
但只有这种转换:
int a ...
Object ans = (Integer) a;
我明⽩为什么你可以在Object to Integer之间进⾏转换,但为什么是原始变量 – 有时你可以,有时候你不能进⾏转换?
谢谢
我附加编译器不允许我在int变量和object之间进⾏转换的代码:
/** @return minimum element */
public Object minimum(){
return );
}
public Object minimum(BSTNode node){
if (node.left != null) return minimum(node.left);
return node.data;
}
/** @return maximum element */
public Object maximum(){
return );
}
public Object maximum(BSTNode node){
if (node.right != null) return maximum(node.right);
return node.data;
}
public Object findNearestSmall(Object elem) {
int diff;
diff = (int)maximum() - (int)minimum();
if (compare(minimum(),elem) == 0) return elem;
else return findNearestSmall(,diff);
}
public Object findNearestSmall(Object elem,BSTNode node,int mindiff){ if(node == null) return (int)elem - mindiff;
int diff = (int)elem - (int)node.data;
if(diff > 0 && mindiff > diff) mindiff = diff;
/* Case 2 : Look for in left subtree */
if(compare(node.data,elem)>-1)
return findNearestSmall(elem,node.left,mindiff);
object toelse
/* Case 3 : Look for in right subtree */
return findNearestSmall(elem,node.right,mindiff);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论