?
Solved

Constructor within an Interface?

Posted on 2003-02-24
8
Medium Priority
?
181 Views
Last Modified: 2010-03-31
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
Comment
Question by:gingermeatboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8011290
Not possible
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 75 total points
ID: 8011319
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8011345
This is true and i was about to suggest something along the same lines. What do you want to do?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:gingermeatboy
ID: 8011498
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
 
LVL 5

Expert Comment

by:msmolyak
ID: 8011540
What exactly are you trying to achieve?
0
 

Expert Comment

by:tomArghh
ID: 8011543
Yes, just ask CS to delete them and they'll refund your points.
http://www.experts-exchange.com/Community_Support/
0
 

Author Comment

by:gingermeatboy
ID: 8011641
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
 
LVL 5

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question