Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:49:57+00:00 2026-06-14T20:49:57+00:00

As in subject: Is it proper equals method for my class Java? I have

  • 0

As in subject: Is it proper equals method for my class Java? I have generated it automaticly by Eclipse I don’t know if it makes vector.remove(pracownik) will work correctrly. Or is it wrong to generate it by Eclipse?

import java.util.Date;
import java.util.Vector;

public class Pracownik extends Osoba {
    private String stanowisko;
    private int pensja;
    private Date dataZatrudnienia;

    public Pracownik(Adres adres, String telefon, String imie, String nazwisko,
            int id, Date dataUrodzenia, String stanowisko, int pensja,
            Date dataZatrudnienia) {
        super(adres, telefon, imie, nazwisko, id, dataUrodzenia);
        this.stanowisko = stanowisko;
        this.pensja = pensja;
        this.dataZatrudnienia = dataZatrudnienia;
    }

    public String getStanowisko() {
        return stanowisko;
    }

    public int getPensja() {
        return pensja;
    }

    public Date getDataZatrudnienia() {
        return dataZatrudnienia;
    }

    @Override
    public String toString() {
        return super.toString() + "\nstanowisko=" + stanowisko + "\npensja="
                + pensja + "\ndataZatrudnienia=" + dataZatrudnienia;
    }

    private static Vector<Pracownik> ekstensja = new Vector<Pracownik>();//kolekcja zawierajaca ekstensje

    private static void dodajPracownik(Pracownik pracownik) { //metoda dodajac aobiekt do ekstensji
        ekstensja.add(pracownik);
    }

    private static void usunPracownik(Pracownik pracownik) {//metoda usuwajaca obiekt z ekstensji
        ekstensja.remove(pracownik);
    }



    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pracownik other = (Pracownik) obj;
        if (dataZatrudnienia == null) {
            if (other.dataZatrudnienia != null)
                return false;
        } else if (!dataZatrudnienia.equals(other.dataZatrudnienia))
            return false;
        if (pensja != other.pensja)
            return false;
        if (stanowisko == null) {
            if (other.stanowisko != null)
                return false;
        } else if (!stanowisko.equals(other.stanowisko))
            return false;
        return true;
    }

    private static void pokazEkstensje(){ //wyswietlenie ekstensji przy pomocy petli for each
        System.out.println("Ekstensja klasy Pracownik");
        for(Pracownik pracownik: ekstensja)
            System.out.println(pracownik);
        System.out.println();
    }

    public static void main(String[] args){
        Adres adres = new Adres("tara", "588 m.42", "03-422", "Warszawa");
        Pracownik pracownik = new Pracownik(adres, "02-6451-4564", "Ala", "Kotowa", 323, new Date(), "szef", 14000, new Date()); //tworze pracownika
        System.out.println(pracownik);//wyswietlam pracowanika

        //tworze stazyste
        Stazysta stazysta = new Stazysta(adres, "3232 9898", "frajer", "costam", 3232, new Date(), "podawanie kawy", 0, new Umowa(new Date(2010,10,5), new Date(2011,11,8)));
        //wysswietlam stazyste
        System.out.println(stazysta);
    }



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:49:58+00:00Added an answer on June 14, 2026 at 8:49 pm

    I am not expert on this but I believe double equals are comparing address rather than content of a variable. So, you may change it to .equals(). I hope someone with much more experience correct me if I am wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely rookie in XPath (I don't even know how to paste proper html
Sorry for unclear subject but i really don't understand where problem. I use a
I cant even come up with a proper subject for this one... Basically I
I am curious as to the proper method for sending multiple pieces of data
Hi as the subject reads System.getenv(HOME) in my action class (struts2) and deploy that
I know the term Load Balancing can be very broad, but the subject I'm
In a model say Task , I have following validation validates_presence_of :subject, :project, :user,
In Java, it is very easy to code the following design: public abstract class
I basically have two child classes which have the same parent class. what I
I have my service in the proper folder (i have an email plugin, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.