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 9084785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:04:59+00:00 2026-06-16T21:04:59+00:00

I require clarification on String[] comparison inside Object’s equal method. Below is my code

  • 0

I require clarification on String[] comparison inside Object’s equal method.
Below is my code snapshot. When I execute this code, it gives true and false instead of true and true.
Also in my case Task class generate unique id for each call.
What am I doing wrong? any suggestion would be appreciated.

public class JobTask extends Task {

    String[] args;

    public WFTask(String[] args) {
        this.args = args;
    }
    @Override
    public boolean equals(Object obj) {        
            if (! ( obj instanceof String[] ) ){
            return false;           
            }
            String[]  arguments = (String[] ) obj;
            boolean ret = Arrays.equals(this.args , arguments );
            return ret;
    }
    @Override
    public void execute(TaskExecutionContext context) throws RuntimeException {
            --------------
            --------------
    }
    public static void main(String[] args) {
            String[] arg1 = {"a","b","c"};
            String[] arg2 = {"a","b","c"};
            System.out.println( Arrays.equals(arg1,arg2));
            JobTask t1 = new JobTask(arg1);
            JobTask t2 = new JobTask(arg2);
            System.out.println( t1.equals(t2));
    }
}

public abstract class Task {
    private Object id = GUIDGenerator.generate();
    public Task() {
    }
    Object getId() {
       return id;
    }
    public abstract void execute(TaskExecutionContext context)                  throws RuntimeException;
}
  • 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-16T21:05:01+00:00Added an answer on June 16, 2026 at 9:05 pm
    @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            JobTask other = (JobTask)obj;
            if (!Arrays.equals(args, other.args))
                return false;
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require 'coderay' puts CodeRay.scan('puts Hello, world!', :ruby).page This code will print full HTML page
Suppose I have this code: static void Main(string[] args) { var thread = new
Require a huge help here, since this is affecting our production instance. One of
I require ASP.NET server side code in a SVG that I created. To accomplish
If my domain object should contain string properties in 2 languages, should I create
So I have this huge tree that is basically a big switch/case with string
Consider a simple POJO Java Object: class MyObj { String a, b; Integer c;
I require some clarification on the question why do we need the scope resolution
Clarification : As per some of the comments, I should clarify that this is
I am writing a piece of code that to work would require an extensive

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.