• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Constructor within an Interface?

Is it possible to have a constructor within an interface?
This isn't absolutely essential to my current program but would make a difference interms of speed, all I want the interface to contain is a boolean value but thecompiler doesn't seem to like this:

public interface HostInterface extends Remote
{

    boolean dead;

    HostInterface()
     throws RemoteException
    {
     this.dead = false;
    }

....
}


Any ideas? or is this just plain not possible?

Thanks
0
gingermeatboy
Asked:
gingermeatboy
  • 3
  • 2
  • 2
  • +1
1 Solution
 
CEHJCommented:
Not possible
0
 
msmolyakCommented:
Interfaces do not allow constructors. What you acn do is to create an abstract class implementing this interface and put this constructor there. Even though the abstract class cannot be instantiated, but the concrete classes extending it can reuse that constructor.
0
 
CEHJCommented:
This is true and i was about to suggest something along the same lines. What do you want to do?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gingermeatboyAuthor Commented:
yeah, I didn't think that'd be possible! don't really think there's anyway to do what I want using an abstact class either so it doesn't matter, sorry about all the duplicate posts! I was hitting refresh to look for replies not realising that it was re-registering the question! any way to remove the other ones?
0
 
msmolyakCommented:
What exactly are you trying to achieve?
0
 
tomArghhCommented:
Yes, just ask CS to delete them and they'll refund your points.
http://www.experts-exchange.com/Community_Support/
0
 
gingermeatboyAuthor Commented:
why, ok.... using RMI have made a peer to peer type relationship between a dispatcher and workers, dispatcher's running whenever a worker starts up it registers with the dispatcher and these can be used by my code to distribute working that i've to do, however I've got to use a dead boolean incase one dies I can deal with it in the try catch. Now, for the RMI connection I've got this :

Registry  registry = LocateRegistry.getRegistry(((workerHost)worker).hostName, 1099);
Object           o = registry.lookup("Worker");
HostInterface h = (HostInterface)o;

now, I think that this process being done hundreds of time must have a time overhead which I'm trying to cut down, so I thought it might be possible for the dispatcher just to pass back what in the above example is denoted by h, rather than doing this every time. Didn't really think it'd work but thought it was worth a try! :)


0
 
msmolyakCommented:
Again, why can't you create a super abstract class for your classes implementing HostInterface and put the boolean flag there?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now