According to the Java Language Specification:
String contexts apply only to an operand of the binary + operator which is not a String when the other operand is a String.
The target type in these contexts is always String, and a string conversion (§5.1.11) of the non-String operand always occurs.
Which means that when you do hp + brand
, since brand
is a String
the rule above kicks in, hp
gets converted to a String
and concatenation occurs, resulting in a String
.