Aleksey Movchan wrote:MyClass[] myArray is a coordinate points array (x,y), and it's possible to put (x,y) there, but impossible (at least for me) to get them from this class. It has only constructor, but not getters or setters.
So, actually, I just don't know how to duplicate MyClass variable without refferencing it.
Stephan van Hulst wrote:If you can't modify objects of MyClass, then you don't have to worry it either, right? All you need to do, is copy an array without calling any methods to do it.
The key point is "If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object.".
https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
The key phrase is "create copies of your internal mutable objects when necessary to avoid returning the originals in your methods."
You may not call any library functions other those in java.lang, java.util, and algs4.jar. In particular, you may call Arrays.sort().
I was born with webbed fish toes. This tiny ad is my only friend:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|