简体   繁体   中英

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.

In my client class MyClass , I created an anonymous object of type MyData , and passed it to the remote method, and got an exception:

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? 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
  2. The class within which it is defined is Serializable , and
  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.

Don't do this. There is no advantage, and several disadvantages. Use an outer or static class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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