温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Oracle OCA J2SE7 Cetificate - Rules for Primitive Types

发布时间:2020-07-16 18:51:51 来源:网络 阅读:407 作者:码上吹 栏目:关系型数据库
  • 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.


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI