Reputation: 6658
Say I'm debugging a program and I see a variable (A custom class object) in the variable pane. Is there a way to quickly convert that variable to a code which would create that instance at a later point in time?
Eg:
class person{
private List<Address> address;
private String name;
private int age;
..constructors, getters and setters
}
class Email{
private String StreetNo;
private String StreetName;
private String City;
private String State;
private String zip;
..constructors, getters and setters
}
Say in the variable pane (while eclipse debug) I handle an instance of Person object. How to (Is here a way to) quickly convert that instance into code like
Person test1 = new Person (...);
input for this constructor should be from the debug session.
Display pane only can print this objet, how do I convert that object value into a constructor code (using reflection, possible?)
Upvotes: 1
Views: 147
Reputation: 2909
No, such a thing would not be feasible because there is no guarantee that an object of any given class, preserving its state, can be recreated by code like in the way you want using a constructor, or even by successive calls to its methods.
What you could do, though, midway through debugging, if the class implements the Serializable interface, is serialize the object to a file, for example, which you could then deserialize whenever you want later. That is one way you could persist the object.
Upvotes: 1