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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:20:28+00:00 2026-05-24T16:20:28+00:00

It is best practice not to expose the internal references of an Object (Entity).

  • 0

It is best practice not to expose the internal references of an Object (Entity). So if an Object has a field of type java.util.Date then for example the getter for this field should return not the original date but an copy of it.

But for an java.util.Date there are two common ways to create that copy:

  • clone: (Date) originalDate.clone()
  • copy via constructor new Date(originalDate.getTime())

My question is, which way is better, and why?

  • 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-24T16:20:29+00:00Added an answer on May 24, 2026 at 4:20 pm

    If it’s definitely just a Date, it won’t make any difference either way.

    If the actual object might be a subclass of Date (such as java.sql.Date) then I’d hope that clone() would preserve the extra information (including which class it is) whereas calling the constructor wouldn’t.

    As an aside, if you used Joda Time you wouldn’t have this problem, as there are plenty of immutable types to use. It’s also a much better API 🙂

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

Sidebar

Related Questions

This pertains to C# & the .NET Framework specifically. It's best practice not to
I'm learning Grails/GORM and as I've understood it the current best practice is not
I know this sort of code is not best practice, but nevertheless in certain
It may not be best practice but are there ways of removing unsused classes
Is there a best practice in regards to returning (or NOT returning datasets) from
This is clearly not appears like it wouldn't be a best practice. Can someone
I'm faced with the following and I'm not sure what's best practice. Consider the
according to anti-if campaign it is a best practice not to use ifs in
According to anti-if campaign it is a best practice not to use ifs in
What is the best practice for not breaking builds for team members working on

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.