I know this probably sounds quite basic but I am very new to Java.
I wish to set an objects field value to the same field in a new similar object. How do I do this please.
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Based on your comment, since you are duplicating an instance, you should probably create a copy constructor. That is a constructor that takes an instance of the class, and bases the fields of the new instance off the fields of the original. Here is a simple example.
However, if this instance is an object that is being saved, usually fields like
createDatereflect the date of the copy, not the date of the original, but it doesn’t have to be that way.