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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:44:58+00:00 2026-05-23T19:44:58+00:00

I have created a clone of an object in my code. Class<?> oc =

  • 0

I have created a clone of an object in my code.

Class<?> oc = o.getClass();
Object preStateInstance = oc.newInstance();

Now I have to output a Java file and I would like the created file to have an assignment of that cloned instance. Something like:

Object varX = preStateInstance.value;

Is that possible? How?

What I am trying to do is to create test cases. I want to save an instance of the object under test as a pre state value, in order to be able to compare the before and after state of an object. I have done it in my code, now I need to output it to a JUnit file. On the class that handles JUnit file writing I only have access to preStateInstance.

EDIT: I think I still have not made myself clear. My JUnit writer requires me to pass on a string so that he will output it to a complete JUnit file. After cloning the instance I would have to tell my writer how to initialise it in it’s file.

  • 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-23T19:44:59+00:00Added an answer on May 23, 2026 at 7:44 pm

    To create a clone you’ll have to implement the Cloneable Interface and a clone method which creates the new object and copies the necessary attributes.

    For your Unit-Tests however, I’d recommand some kind of serialization, have a look at XStream (http://x-stream.github.io/) It converts an object into XML and vice versa, allowing you to even edit the XML in between – just perfect for test cases IMHO.

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

Sidebar

Related Questions

I have created a C# class file by using a XSD-file as an input.
Actually i have created an singleton class. Now my singleton class extends Activity, and
I have a local git repository created with git svn clone . I make
I have the following code that is able to create a class that has
I have the following windows service file: Imports System.ServiceProcess Imports System.IO Public Class fswService
I have created a custom even class which is pretty basic. But when calling
I have created a function that takes a SQL command and produces output that
I have main activity which call other object, for example GPS class. This GPS
I have a prism/wpf/mef solution that contains an AvalonDock. I created a RegionAdapterBase<Pane> class
My question is, In my code I have made a JTable in main class.

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.