Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rmi and inner calsses

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic