'Redundant local variable' inspection quirk
'Redundant local variable' inspection has a quirk with autoboxing:
IDEA says that 'j' is redundant, but inlining 'j' changes the semantics of the code as after inlining 'k' and 'l' do not reference to the same object!
请先登录再写评论。
Mileta Cekovic wrote:
In fact, in this very special case IDEA is correct because
even after inlining 'j', the value of 'eq' is always 'true'.
This "feature" has been discussed in many places on the web,
e.g. in http://www.davidflanagan.com/blog/000022.html.
(Of course, when you replace the first line with something
like int i = 168, IDEA is most likely to err in saying
"Condition 'k == l' is always 'true' (but that may depend
on the compiler).)
Regards,
Jens