java.lang.classcastexception怎么解决,java:ClassCastException-[Ljava.lang.Long;不能强制转换为java.lang.Long...

I use red5 and setting/getting attributes using the IConnection class, but that's really not relevant.

'L' means long in java. so 0L is 0 type Long instead of just '0' which is 0 type Integer.

What is the difference between [Ljava.lang.Long and java.lang.Long in the following error message:

stack trace: java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.lang.Long

update

code sample:

static Long getLongAttribute(IConnection conn, String attribute) {

Long result=null;

try {

if (!conn.hasAttribute(attribute))

throw new Exception(attribute + " - Long attribute not found!");

result = conn.getLongAttribute(attribute); //

} catch (Exception e) {

_handleException(e);

}

return result;

}

解决方案

The first object is array of Long, the second is just Long. Try this

Long l = 1l;

Long[] l2 = {};

System.out.println(l.getClass());

System.out.println(l2.getClass());

Output

class java.lang.Long

class [Ljava.lang.Long;

But I do agree that [L_class_; presentation for array types is highly confusing. I wonder how it came to be that way.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值