Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Interfaces

Options
  • 19-11-2004 7:29pm
    #1
    Registered Users Posts: 811 ✭✭✭


    HEy. I have an interface class called EmployeeObserver and i have an Employee Class that implements this.I get this error message.
    Employee.java:4: Employee is not abstract and does not override abstract method
    equals() in EmployeeObserver
    Equals is declared as a boolean in the interface and is defined in the class.It worked fine until i added the interface.
    Anyone have any idea how to get round this?
    Cheers


Comments

  • Registered Users Posts: 6,316 ✭✭✭OfflerCrocGod


    At a guess you have a problem with the way you implemented equals(). In the interface it's probably different....you may not be actually implemeting what you have in the interface. Post the code and it may become clearer.


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    wonderboy wrote:
    HEy. I have an interface class called EmployeeObserver and i have an Employee Class that implements this.I get this error message.
    Employee.java:4: Employee is not abstract and does not override abstract method
    equals() in EmployeeObserver
    Equals is declared as a boolean in the interface and is defined in the class.It worked fine until i added the interface.
    Anyone have any idea how to get round this?
    Cheers
    check that your signatures match
    i.e if your interface takes in two Employee objects but your Employee:equals() method takes in two Strings.

    Post some code and we will spot it for ya straight away.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    CA4 Wonderboy? OO Software Patterns project?


  • Registered Users Posts: 811 ✭✭✭dave13


    Here's a segment of the employee class including the equals method
    import java.io.Serializable;

    public class Employee implements Cloneable, Serializable, EmployeeObserver
    {
    public boolean equals(Object o)//Overrides the equals operator
    {
    if(o==null)
    {
    return false;
    }

    Employee em;
    try{
    em = (Employee)o;
    }
    catch(ClassCastException e){
    return false;
    }
    if(name.equals(em.name))
    {
    return true;
    }
    return false;
    }
    }

    And heres the interface
    public interface EmployeeObserver
    {
    void receive();
    Object clone();
    boolean equals();
    }
    And yes CA4. This is all thats holding me up
    Any advice appreciated


  • Registered Users Posts: 6,316 ✭✭✭OfflerCrocGod


    Firstly use generics, secondly in the interface Object o is missing boolean equals(Object o); should work. Try it.


  • Advertisement
  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Also shouldn't it be...

    public boolean equals(Object o);

    Also do any of the other interfaces implement the equals(Object o) method?


  • Registered Users Posts: 261 ✭✭HaVoC


    Firstly use generics, secondly in the interface Object o is missing boolean equals(Object o); should work. Try it.

    generics are only available in java 1.5, your college may not have it installed as its fairly new.


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Everthing in an interface is implicitly public anyway so it doesn't really matter.
    The other interfaces are just markers, they don't declare any methods.


  • Registered Users Posts: 6,316 ✭✭✭OfflerCrocGod


    HaVoC wrote:
    generics are only available in java 1.5, your college may not have it installed as its fairly new.
    I know so you just install it. All my code is Java 5, God I love Generics :) and I really don't care what the college uses, do your own stuff.


  • Hosted Moderators Posts: 2,094 ✭✭✭halenger


    Gotta love this project. *cries*

    Painful... Scrapped my code twice now I think it is and moving onto a 3rd attempt. Overcomplicating this everytime. Think I've an idea now but looking for a suitable pattern.


  • Advertisement
  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    Firstly use generics
    *IF* you are using jdk 1.5+
    also, how would Generics help in this case? :confused:


  • Registered Users Posts: 811 ✭✭✭dave13


    Thanks for the help.Got it working.H
    Home and dry(I think).


  • Registered Users Posts: 6,316 ✭✭✭OfflerCrocGod


    GreeBo wrote:
    also, how would Generics help in this case? :confused:
    It's just better/nicer all this "Object" crap is horrid.


  • Registered Users Posts: 20,993 ✭✭✭✭Stark


    Yeah you don't have to do casting and type checking is done at compile time rather than runtime so "Classcastexceptions" will be a thing of the past.


  • Registered Users Posts: 261 ✭✭HaVoC


    It just some lectures bitch over using a differant jdk then class happened to a friend of mine he used 1.4 and college was 1.3 he used a 1.4 feature that made the assignment easier and he only got 50%. but sense your a 4th year u shouldnt get that crap.


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    It's just better/nicer all this "Object" crap is horrid.
    Yeah, but how do Generics help you to override the equals method?


Advertisement