• 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

method over-riding; compilation error

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have following classes in db package.
public interface DBInterface
public class Data implements DBInterface
public interface DBRemoteInterface extends Remote, DBInterface
public class DBServer extends UnicastRemoteObject implements DBRemoteInterface
DBInterface has all public methods of Data class
DBRemoteInterface also has all public methods of Data class, the only difference is, it additionally throws RemoteException
I have not yet implemented logic in lock, unlock methods, so they are empty in Data class.
DBServer class has a reference to Data, and all methods of DBServer call the corresponding methods on this instance variable.
I am getting compilation error while compiling DBServer class. Following is the error :
unlock(int) in suncertify.db.DBServer cannot implement unlock(int) in suncertify.db.DBInterface; overridden method does not throw java.rmi.RemoteException
public class DBServer extends UnicastRemoteObject implements DBRemoteInterface{
Can someone please give some explanation, as to why I am getting this error ?
Thanks in advance
 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me add that, moment I remove DBInterface from extends clause of DBRemoteInterface, everything compiles fine.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rasika,
An overridden method can not throw more exception than the method
what it override! (and vice-versa)
I think yous should use an adapter. (See Adapter pattern.)
Anyhow, I look forward the others opinion also, to see what
other solutions are possible.
Ban
 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am surprised at is DBRemoteInterface compiles fine even when it is a sub-interface of DBInterface, what gives compilation error is DBServer
 
reply
    Bookmark Topic Watch Topic
  • New Topic