Calling a method and passing an object reference and catching the return with same reference

I have a beginners question. I searched a lot for the answer but can't seem to find the exact answer so maybe somebody of more experienced developers can help me with this one.

So, let's say you have a following situation in code (this is simplified version of the situation):

SomeObject a1 = new SomeObject();
a1 = someMethod(a1);

public SomeObject someMethod(SomeObject a1) {
 a1.changeVariable();
return a1;
}

now I heard from several people saying that passing a reference to an object to a method and catching the return value is bad coding practice. Unfortunately nobody can exactly explain to me why it is bad coding practice, and my search for the reason came up with nothing. Can some explain why it is bad practice to do this? I can not think of a situation where something for this can go wrong.

Thanks in advance, you nice people have already helped me with answers to other people countless times, this is a first time I actually needed to post a question :)

Jon Skeet
people
quotationmark

In the scenario you've shown, there isn't much obvious benefit. However, as a pattern it can be useful in my experience - particularly if the method performs validation.

Guava's Preconditions.checkNotNull method is a great example of this. It means I can write code like this:

public class Player {
    private final String name;

    public Player(String name) {
        this.name = Preconditions.checkNotNull(name);
    }
}

... instead of having to split the assignment and the validation. It also allows validation to exist as part of another call, e.g. to another constructor:

super(Preconditions.checkNotNull(name));

people

See more on this question at Stackoverflow