Java widening conversions

后端 未结 5 1009
时光取名叫无心
时光取名叫无心 2020-12-28 14:55

I\'m preparing for Java 7 certification and have the following question.

Byte b = 10 compiles ok. Looks like the compiler is narrowing int 10 to byte 10

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 15:31

    Byte constructor takes either byte type or String type. See this

    Constructor for Long takes long as an argument. Since long can take in integer, it allows it in the constructor.

提交回复
热议问题