I am creating an object in Java. One of its attributes is a grid reference – ints x, y & z.
Rather than creating a variable for each, is there a better way to store these?
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.
Create a record-like class, GridReference:
You could instantiate it as:
And assign the individual values via:
Accessible via:
You could flesh the class-out to a more secure object as:
And instantiate it as:
Assigning the values at the same time. These would be accessed via:
(To change the values, you’d need to reassign the reference to a new GridReference though.)