简体   繁体   English

是否可以将匿名对象作为RMI方法的参数传递?

[英]Is it possible to pass an anonymous object as argument of an RMI method?

I am trying to invoke a remote method via RMI that takes 1 argument of type MyData , which is an interface known in both server side and client side. 我试图通过RMI调用一个远程方法,该方法采用类型为MyData 1个参数,这是服务器端和客户端都已知的接口。

In my client class MyClass , I created an anonymous object of type MyData , and passed it to the remote method, and got an exception: 在我的客户端类MyClass ,我创建了一个MyData类型的匿名对象,并将其传递给远程方法,并得到一个异常:

Caused by: java.lang.reflect.InvocationTargetException
    at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:795)
    at 
    ... 2 more
Caused by: java.lang.ClassNotFoundException: MyClass$1 (no security manager: RMI class loader disabled)

Question: Must I use an implementation of the interface MyData to pass RMI method argument? 问题:我必须使用MyData接口的实现来传递RMI方法参数吗? That implementation is known on both server and client sides. 实现在服务器端和客户端均已知。

It's possible if: 如果可能,则:

  1. The class is deployed to the CLASSPATH of the peer, or available via the codebase feature, and 该类已部署到对等方的CLASSPATH,或者可通过代码库功能使用, 并且
  2. The class within which it is defined is Serializable , and 定义它的类是Serializable并且
  3. You realize and accept that the outer class instance will be sent along with the anonymous class, because it's an inner class and has a reference to its outer class, and therefore that the outer class also has to be deployed to the peer or available via the codebase feature. 您意识到并接受外部类实例将与匿名类一起发送,因为它是内部类,并且对其外部类有引用,因此外部类也必须部署到对等方或通过代码库功能。

(2) May not be true, and may not need to be true for any reason other than this, and (3) is very likely to be untrue, as it is very likely to be a client-only class that is none of the server's business. (2)可能不是正确的,并且可能由于其他原因而不必是真的,并且(3)很可能是不正确的,因为它很可能是仅属于客户端的类,而没有服务器的业务。

Don't do this. 不要这样 There is no advantage, and several disadvantages. 没有优势,也有几个劣势。 Use an outer or static class. 使用外部或静态类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM