Although I have been programming C, C ++ and C # for many years, I am only superficially familiar with Java. Helping my comp Sci son with a Java college project, he had to return references to two objects from a method in Java. I suggested returning it as a function value, and the second as a link. He did not know how to do it. I did a little research and realized that it would be impossible. My question is in Java, what is the general method used when a method should return more than one object reference. Here is a concrete example in my case with sons.
// This method returns references to the head and tail objects from the passed in // linked list. The head object is returned as the function value and the tail is // returned as a parameter. public Static Node GetHeadTail(List list, Node tail)
I understand that the above does not work in Java, since the tail is a node reference, and in Java this link is passed by value. What is the most common way to handle this in Java? My son's solution was to return an array of 2 node objects for the function value. I said that this is a bad decision because it does not document the value of each element of the array. Another solution would be to create an object containing references to the head and tail. However, in the specific example, this was the main pointer that was of the most interest, and if the object were returned, it would create undesirable coding overhead for the calling method if all they wanted was a voice.
source share