Reputation: 181
In a server programmed in Java, I found this statement:
buffer = buffer = new byte[bufferSize];
What I don't understand is that "buffer = " is stated twice.
Would not this code do the exact same thing?
buffer = new byte[bufferSize];
Thanks.
Upvotes: 0
Views: 75
Reputation: 15445
Java assignment (=
) is evaluated right-to-left so,
buffer
is assigned to new byte[bufferSize]
buffer
is assigned to the value of buffer
While the second statement is exactly as you'd expect. buffer
is assigned to new byte[bufferSize]
.
It's likely the compiler would optimize this away.
Upvotes: 3