java:ClassCastException-[Ljava.lang.Long;不能强制转换为java.lang.Long [英] java: ClassCastException - [Ljava.lang.Long; cannot be cast to java.lang.Long
本文介绍了java:ClassCastException-[Ljava.lang.Long;不能强制转换为java.lang.Long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用red5并通过IConnection类设置/获取属性,但这确实无关紧要。
'L'表示Java的所以0L是0类型的Long,而不仅仅是'0',它是0类型的Integer。
'L' means long in java. so 0L is 0 type Long instead of just '0' which is 0 type Integer.
[Ljava.lang.Long和有什么不一样?
和 java.lang.Long
在以下错误消息中:
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
更新
代码示例:
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); // <--- ERRROR ON THIS LINE
} catch (Exception e) {
_handleException(e);
}
return result;
}
推荐答案
第一个对象是 Long
,第二个就是 Long
。试试这个
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());
输出
class java.lang.Long
class [Ljava.lang.Long;
但我确实同意 [L_class _;
数组类型的表示非常混乱。我不知道是怎么回事。
But I do agree that [L_class_;
presentation for array types is highly confusing. I wonder how it came to be that way.
这篇关于java:ClassCastException-[Ljava.lang.Long;不能强制转换为java.lang.Long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文