DEV Community

Discussion on: The Behavior of `i = i++` in Java

Collapse
 
jakebman profile image
jakebman

This is definitely a good habit in C++, where you can overload ++i and i++.

If you are using a custom type, i++ is required to return a temporary object representing the old state of the object, whereas ++i is allowed to 'increment' the i object and return the same object.

Compilers might be able to figure this out, but it's better to not make them do so.