Java中的(Integer)y和new Integer(y)有什么区别?
2022-09-04 01:32:55
以下有什么区别:
Integer in = (Integer)y;
和
Integer in = new Integer(y);
我想将类型转换为类型,反之亦然。以下是我执行此操作的代码:int
Integer
public class CompareToDemo {
public static void main(String[] args) {
// Integer x=5;
int y=25;
System.out.println(y+" this is int variable");
Integer in = (Integer)y;
//Integer in = new Integer(y);
if(in instanceof Integer){
System.out.println(in +" this is Integer variable");
}
}
}