[英]com.sun.proxy.$proxy0 cannot be cast to XXX
I was writing a RMI application.我正在编写一个 RMI 应用程序。 I have a method on the server side, which returns an
ArrayList<User>
and User
is a class I defined myself.我在服务器端有一个方法,它返回一个
ArrayList<User>
并且User
是我自己定义的 class。 The code is like: list = obj.getList(); System.out.println(list.get(0).getName());
代码如下:
list = obj.getList(); System.out.println(list.get(0).getName());
list = obj.getList(); System.out.println(list.get(0).getName());
, and this line generated an exception of "com.sun.proxy.$Proxy0 cannot be cast to User". ,并且此行生成“com.sun.proxy.$Proxy0 无法转换为用户”的异常。 Can anybody help me about that?
有人可以帮我吗?
If User
is an exported remote object, as it seems to be, it appears in the client as the remote interface it implements, not as the implementation class. 如果
User
是一个导出的远程对象(看起来如此),则它在客户端中显示为它实现的远程接口,而不是实现类。
So that's what you must cast it to. 这就是您必须将其投射到的内容。 In this case that means declaring your List as
List<UserInterface>
, where UserInterface
is the name of the remote interface. 在这种情况下,这意味着将您的列表声明为
List<UserInterface>
,其中UserInterface
是远程接口的名称。 Adjust to suit. 调整以适合。
I remember I had this problem before.我记得我以前遇到过这个问题。 I added
extends Remote
at the end of public interface nameOfYourInterface
.我在
public interface nameOfYourInterface
的末尾添加了extends Remote
。 It worked for me.它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.