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

  • SEARCH
  • Home
  • 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 8588627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:51:00+00:00 2026-06-11T22:51:00+00:00

I am thinking of using a Set of BusinessObjects in Java. My intention is,

  • 0

I am thinking of using a Set of BusinessObjects in Java. My intention is, that in each set there should be only ONE instance of each business object, but one business object can be shared across many sets. So, as an example:

BO1 - instance of BusinessObject1
BO11 - instance of BusinessObject1
BO2 - instance of BusinessObject2

this is correct

[BO1, BO2] or [BO1]

but this isn’t
[BO1, BO11]

Since I wanted to make sure this is enforced, I was thinking of specifying an AbstractBusinessObject like this:

public abstract class AbstractBusinessObject {

    @Override
    public int hashCode() {
        return this.getClass().getName().hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null)
            return this.getClass() == obj.getClass();
        return false;
    }
}

Do you think that is a good idea?

  • 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-11T22:51:01+00:00Added an answer on June 11, 2026 at 10:51 pm

    Why not simply use Enums?
    You can use Enum of business objects and EnumSet of Business Objects.

    public enum Day {
        SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
        THURSDAY, FRIDAY, SATURDAY;
        static final EnumSet<Day> weekend = EnumSet.of(SATURDAY,SUNDAY);
    }
    

    Tutorial here

    Now if your business object are not designed for above purpose then just implement equals and hashcode in a normal way.
    HashSet add method will anyway ignore duplicates.

    This link discusses about equals and hashcode contract.

    For Business objects general rule is equals and hashcode needs to be implemented using your business object PK.

    Like For Employee object employee number can be considered as business key and pk can be different so equals and hashcode should based on employee number.

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

Sidebar

Related Questions

I'm thinking about using the java application object to implement a simple cache, to
I was thinking of using a far jump to set the code segment (CS)
I was previously using the application object to cache data that never changes. I
I am developing a small web app that should receive emails from users, using
I am thinking of using BigDecimal to compare two currency values rounded to 2
I'm thinking about using Redis as a store for some highly transient data (we're
I was thinking of using a Double as the key to a HashMap but
I was thinking of using AUTONOMOUS_TRANSACTION Pragma for some logging in a batch process.
I'm thinking of using Google Docs as a content management system, and to integrate
I am thinking about using Gears in a project, but I have doubts about

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.