• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method over-riding; compilation error

 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Let me add that, moment I remove DBInterface from extends clause of DBRemoteInterface, everything compiles fine.
 
Andras Nemeth
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic