Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 516

Answer by Federico klez Culloca for Question about the behavior of toString on integers

$
0
0

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.


Viewing all articles
Browse latest Browse all 516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>