Using methods from a interface implemented class

Discussion in 'Plugin Development' started by Randy Schouten, Nov 15, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Randy Schouten

    Well that's a mouthfull.

    So, I have a Interface, and I implement it in 2 other classes.
    I want to use the methods in those 2 classes, but I can't seem to get it working.

    It says it should make the method static, so I do that, but then it says that the method can't be static because it cannot hide the instance method(?).

    Any help would be appreciated. :)
     
  2. Sounds like your using interfaces wrong....post your code
     
  3. Offline

    Randy Schouten

  4. Offline

    desht

    Interfaces shouldn't contain instance variables (your taskTypes and taskTypesList), for a start. I notice your implementing class doesn't make any reference to them in any case. Why do you need them in your interface there?

    Quoting the official docs: In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types.

     
  5. Offline

    Randy Schouten

    Right.
    I didn't know that.
    I have it there as the stuff in that hashmap is used for quests in general.
     
  6. Offline

    desht

    Obviously I don't know the ins and outs of your design, but I wonder if you might be better served by an abstract base class rather than an interface here. You can put any common instance fields in your base class.

    If an interface really is what you need here (e.g. are you making a public API from this?), you could create an abstract base class which implements that interface. Being abstract, it doesn't need to provide implementations for all (or even any) of your interface methods - that can be left to the concrete subclasses.
     
  7. Offline

    robertmarks62

    An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
    An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
    abstract void moveTo(double deltaX, double deltaY);
    If a class includes abstract methods, the class itself must be declared abstract, as in:
    public abstract class GraphicObject { // declare fields // declare non-abstract methods abstract void draw(); }
    When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.
     
Thread Status:
Not open for further replies.

Share This Page