Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making java.rmi.Remote and java.lang.Comparable get along  RSS feed

 
Jason Ferguson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'm using java.rmi.Remote and have created interfaces IAccount and ITransaction (with appropriate implementations).

However, the rule for any class implementing Remote is that all methods have to throw RemoteException. This means that the class cannot implement Comparable, because compareTo() in Comparable does not throw RemoteException.

What I'm trying to do is obtain an Account instance, which will contain a Collection of transactions. I'll then create my Transaction(s), then add it to the Collection, which I would like to be a TreeSet. I can't use a TreeSet if I can't implement Comparable.

Anyone have any ideas?
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an implementation of java.util.Comparator instead.

It exists mainly for these kinds of reasons: the class you want to compare is not comparable, either because the programmer didn't think it was necessary or because it's not possible, or you want some other custom comparing.


However, I have some doubts on your design. The Account instances seem to be objects you transfer through RMI, not the RMI server itself. So why does it need to implement Remote itself? It's like having web pages that are web servers themselves.
 
Jason Ferguson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.

I left some of the story out to minimized what I put in the original message.

I didn't want to add another class in this case, but I might try it as an anonymous inner class when defining the TreeSet using the constructor that takes a Comparator...

Jason
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!