Passing char into a method with an int parameter

前端 未结 8 2065
庸人自扰
庸人自扰 2020-12-11 17:38

The output from the following code is 123 because substring takes from beginIndex to EndIndex - 1. However, I am surprised how char

8条回答
  •  有刺的猬
    2020-12-11 17:54

    This goes all the way back to C, where char is in essence a narrow integer type and gets implicitly converted to int whenever necessary.

    In Java, this is technically known as a "widening primitive conversion", and is covered in section 5.1.2 of the JLS.

提交回复
热议问题