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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:16:06+00:00 2026-05-13T16:16:06+00:00

I have a class that implements a 2Dtable. The elements in the table is

  • 0

I have a class that implements a 2Dtable. The elements in the table is generic. And the table is stored like this:

public Object[][] list;

The problem is that calling clone on this apparently doesn’t work. Note that my testcase initializes the table to store normal Integers.

Tabell2D<Integer> en = new Tabell2D<Integer>(5,5);
        en.sett(0, 0, 55);
        Tabell2D<Integer> to = en.clone();
        to.sett(0, 0, 11);
        assertTrue(en.equals(to)); 

Here I make a table. Change it, clone it. Change the clone, and compare them.
Obviously the clone is changed. Even so, this assertTrue is well true.

The equal method is generated by eclipse:

public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Tabell2D other = (Tabell2D) obj;
        if (bredde == null) {
            if (other.bredde != null)
                return false;
        } else if (!bredde.equals(other.bredde))
            return false;
        if (høyde == null) {
            if (other.høyde != null)
                return false;
        } else if (!høyde.equals(other.høyde))
            return false;
        if (!Arrays.equals(liste, other.liste))
            return false;
        return true;
    }

I assume that the problem is either in the compare of the list variable in equal, or the problem is in the clone method.
Clone method:

public Tabell2D<E> clone(){
        Tabell2D<E> nyTab = new Tabell2D<E>(this.bredde,this.bredde);
        nyTab.liste = liste.clone(); 
        return nyTab; 
    }
  • 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-05-13T16:16:07+00:00Added an answer on May 13, 2026 at 4:16 pm

    I think that the root of the problem is that cloning a 2d array doesn’t go deep. If you want a deep copy of ‘liste’ you need to write your own code to copy each row (or column depending on how you look at it).

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

Sidebar

Related Questions

I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor
I have a class that implements an interface like this; ... = new Location<ICafe>();
Straight to the problem: I have a class that implements two interfaces: public class
Let's say I have a class that implements the IDisposable interface. Something like this:
I have this class that implements FilenameFilter package Logic; import java.io.File; import java.io.FilenameFilter; public
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
I have a class that implements IPermission : public class MySecurityPermission : IPermission {
I have a class that implements an interface. The interface is public interface IRiskFactory
I've tried this a couple ways, the first is have a class that implements

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.