This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes Rmi and inner calsses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Rmi and inner calsses " Watch "Rmi and inner calsses " New topic
Author

Rmi and inner calsses

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi!
I use RMI adn I try to encapsulate some properties from the server side and send them on the client side.For this I have an "encap" interface (it extends Serializable) with a lot of gets/sets.This interface is implemented by a inner class on the server side, the server has a get method with the return type my encapsulate interface.Is this ok or I must build an extern "encap"class.


SCJP, SCJD, SCWCD, OCPJBCD
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Yes, it is possible. There are some wrinkles in some circumstances though... take a look at a discussion on how to set the serialVersionUID on an inner class.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Yeep , I must admit a very ingenious solution.
If I understand good the probmem is (and this is 100% right) an non static inner class can not have static members, and in my case I need the : "serialVersionUID".From here the solution need basics class knowledges.

But with all of this the solution is still hard to "digest" whithout a solid java base and if you'er working in a team ......
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hey , A static inner class CAN NOT derive an other inner class, this because a static inner class has access only on static members so :

.............

public class InnerInstanceBehaviorBaseClass implements Serializable {
protected Outer getOuter() {
return Outer.this;
}
}

public static class MyClass extends InnerInstanceBehaviourBaseClass {
....

where both are inner classes fails on compile because the staitc inner has access only on the static context.

My meaning (at least for the moment) is :
The (non static) inner classes are not serializable.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It compiled fine for me...

You have to the weird constructor in the static inner class for it to work -



You also can use non-static serializable inner classes... but you may run into big problems with versioning (since you can't create the static serialVersionUID without doing the weird static inner class wrapping a regular inner class solution above). With all the hoops you have to jump through though, I would suggest just using regular serializable non-inner classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rmi and inner calsses
 
Similar Threads
RemoteException vs IOException
LocalData,RemoteData
Deploying an RMI application
serialization
cleanup on session expiring