[英]Type Casting in Java for Boxed Class?
With Possible Un-boxing in Java Why can't I Downcast With Integer Class. 使用Java中可能的拆箱功能,为什么不能使用Integer类向下转换。
double a=20.3;
int b=(Integer)a;
It gives me error incompatible Type Conversion. 它给我错误不兼容的类型转换。 My question is why Integer class is not able to Downcast it like 我的问题是为什么Integer类无法像这样向下转换
int b=(int)a;
Does Casting works with class for primitive type in Java? Casting是否可以与Java中的基本类型的类一起使用?
double can't autobox into Integer. double无法自动装箱到Integer。 However, int can autobox into Integer. 但是,int可以自动装箱到Integer中。 See docs here. 在这里查看文档。
double a=20.3;
Integer b = (int) a;
int c = b; // c = 20;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.