获取类转换异常,其中两个类完全相同 [英] Getting class cast exception where both classes are exactly the same

查看:113
本文介绍了获取类转换异常,其中两个类完全相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个JBoss SEAM项目,当我查看表单时出现此错误。

I am doing a JBoss SEAM project and when I view a form I get this error.

java.lang.ClassCastException:
it.cogitoweb.csi.entity.csiorelav.CsiTipoLav cannot be cast to
it.cogitoweb.csi.entity.csiorelav.CsiTipoLav

它总是与屏幕上显示的表格相关的JPA类,它对我来说没有意义为什么它是同一个类,似乎不可能。

Its alway the same JPA class which is related to the form which is shown on the screen, it doesn't make sense to me why is it the same class, it seems impossible.

推荐答案

当两个不同的 ClassLoader 对象加载类时会发生这种情况同名。 Java中两个类的相等性取决于完全限定名称加载它的类加载器。

This happens when two different ClassLoader objects load classes with the same name. The equality of two classes in Java depends on the fully qualified name and the class loader that loaded it.

因此,如果两个独立的类加载器加载来自同一位置的类,那些类型的对象将无法转换为彼此类型,即使它们的类被称为相同。

So if two independent class loaders load classes from the same location, then objects of those types will not be able to be cast to each others type, even if their classes are called the same.

这篇关于获取类转换异常,其中两个类完全相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆