4
Gentlemen, one of the methods of the class Array
has the method sort
.
The method sort
works like this:
Arrays.sort(vetor);
The vector itself is changed, I searched in many places and from what I understand this is passage from value by reference.
In C we use pointers, but what about in Java? How it works?
But it would be possible to pass a primitive type value by reference in Java?
– gato
@cat Just you envelop him in a class.
public class MeuInt { public int valor; }
and thenpublic void meuMetodo(MeuInt x) { x.valor = 5; }
- However, you will hardly do something like this in a real code.– Victor Stafusa
I think it makes sense for primitive type values not to be passed by reference. Since you could simply return a new value, however, if it is a class with a lot of data, returning new values would be more expensive for the machine.
– gato
A direct answer. Thank you, that explains a lot.
– user92257