Oracle OCA J2SE7 Cetificate - Rules for Primitive Types
admin
2023-05-02 17:43:37
0
  • Any bigger than an int can NEVER be assigned to an int or anything smaller than int (byte, char, or short) without explicit cast.


  • Constant values up to int can be assigned (without cast) to variables of lesser size (e.g. short to byte) if the values are representable by the variable.


  • Operands of mathematical operators are ALWAYS promoted to AT LEAST int. (e.g. byte*byte both bytes will be first promoted to int) and the return value will be AT LEAST int.


  • Compound assignment operators (+=, *= etc) have strange ways so ready this carefully: A compound assignment expression of the form E1 op = E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1


  • A char value can ALWAYS be assigned to an int variable, since the int type is wider than the char type.


  • A narrowing primitive conversion may be used if all of the following conditions are satisfied:

    1. The expression is a constant expression of type int.

    2. The type of the variable is byte, short or char.

    3. The value of expression is representable in the type of the variable.

    4. NOTE THAT narrowing conversion doesn't apply to long or double. So, char ch = 30L; will fail althrough 30 is representable by a char.


相关内容

热门资讯

冰箱漏电怎么测 1、可以用灯泡检查法来检测冰箱漏电,将36V灯泡的两根导线,一根接冰箱外壳(无漆处)另一根接大地,如...
电饭煲通电就跳闸怎么回事 如果之前电饭煲从未出现过跳闸现象,此现象为新出现的,有可能是插板或者是电饭煲发生故障导致的。首先可以...
空调外机有温度传感器损坏 最可能是温度传感器泄漏导致的这个原因。可以使用热毛巾加热温度检测管,将按钮设置为最低温度,并使用测试...
九阳铁釜电饭煲故障代码种类及解... 故障代码的种类很多,有E0表示电饭煲上盖热敏电阻故障,需要更换上盖的热门电阻;E1是热敏电阻故障,需...
九阳电饭锅的拆卸步骤 先拆锅底的四个小螺丝,然后将暴露出来的底拆开,然后拆卸电饭锅那儿的小盖板,用螺丝刀拆螺丝就行,然后将...
华南理工男生课堂偷拍女生被当场... 据羊城晚报消息,5月13日,一段“华南理工大学男生教室偷拍女生”视频在网络传播,相关事件引发热议。视...
偷税超900万被查的网红白冰:... 刚刚,因偷税超900万元被查的网红白冰发布近60分钟长视频,控诉前员工联合他人侵吞公司资金、设局陷害...
AI人才需求攀升,如何打开就业... 当前正值高校毕业生求职关键期。记者在劳动力市场看到,随着人工智能蓬勃发展,各行业各领域对AI(人工智...
5月14日、15日土星火星上演... 5月14日、15日土星火星上演合月“接力赛” 5月14日、15日日出前,东方低空将接连上演土星合月...
投身具身智能,它石丁文超:知行... 90后、“天才少年”、博导...它石智航首席科学家丁文超身上有不少标签。他曾参与主导真正意义上的第一...