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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:16:21+00:00 2026-05-14T06:16:21+00:00

A number of times I’ve argued that using clone() isn’t such a bad practice.

  • 0

A number of times I’ve argued that using clone() isn’t such a bad practice. Yes, I know the arguments. Bloch said it’s bad. He indeed did, but he said that implementing clone() is bad. Using clone on the other hand, especially if it is implemented correctly by a trusted library, such as the JDK, is OK.

Just yesterday I had a discussion about an answer of mine that merely suggests that using clone() for ArrayList is OK (and got no upvotes for that reason, I guess).

If we look at the @author of ArrayList, we can see a familiar name – Josh Bloch. So clone() on ArrayList (and other collections) is perfectly fine (just look at their implementations).

Same goes for Calendar and perhaps most of the java.lang and java.util classes.

So, give me a reason why not to use clone() with JDK classes?

  • 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-14T06:16:21+00:00Added an answer on May 14, 2026 at 6:16 am

    So, give me a reason why not to use clone() with JDK classes?

    • Given an ArrayList reference, you would need a getClass check to check that it is not a subclass of the JDK class. And then what? Potential subclasses cannot be trusted. Presumably a subclass would have different behaviour in some way.
    • It requires that the reference is more specific than List. Some people don’t mind that, but the majority opinion is that that is a bad idea.
    • You’ll have to deal with a cast, an unsafe cast at that.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This chart has been linked a number of times on blogs that I follow
How can I display a counter that counts the number of times a file
Does anyone know how to count the number of times a value appears in
I know this question was asked a number of times on this site alone,
How to render specific number of times ? I'm making that my topmenu and
I wrote 3 functions that count the number of times an-element appears in a-list.
Is there a maximum number of times that a DLL can be registered and
I have simplified the following mysql query that counts the number of times a
I have used parameterized query number of times I know it helps in preventing
There are often times when you know for a fact that your loop will

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.