首页 > 编程语言 >Java中 Long 与 Integer 之间的转换 [ClassCastException:Long cannot be cast to integer]

Java中 Long 与 Integer 之间的转换 [ClassCastException:Long cannot be cast to integer]

时间:2022-12-20 22:12:23浏览次数:44  
标签:Long cast ClassCastException cannot Integer integer

 [ClassCastException:Long cannot be cast to integer] 有时数据库操作时经常会遇到这个问题,Long 和 Integer  都是java中的包装类型,包装类型是不能强制转换的。

//Integer型转化为Long型
Integer a = 10;
Long b = a.longValue();

//Long型转化为Integer型
Long a = 10L;
Integer b = a.intValue();

 

标签:Long,cast,ClassCastException,cannot,Integer,integer
From: https://www.cnblogs.com/hungryquiter/p/16995220.html

相关文章