• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic