Java autoboxing rules

前端 未结 4 1694
难免孤独
难免孤独 2020-12-09 06:04

I am a java novice and so confused by the following example. Is it okay to think that \"==\" sign will compare the values between Integers and \"autoboxed\" Integer

4条回答
  •  执笔经年
    2020-12-09 06:43

    == can only be used for checking if the variables are equal or not if the variables are primitive types. For object variables, == is used to compare the reference of the objects. If you want to compare the values of the objects, use .equals() method.

提交回复
热议问题