Java constant expression

Source: Internet
Author: User
Tags logical operators

Original address: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.28

This is my translation for the time being.

A constant expression is an expression that represents a basic data type or a string data type, and is a value that can be computed during compilation. Consists of the following points:

  • The base data type or the literal value of the string data type
  • Convert to basic data type or string (this is not very understanding)
  • Unary operator: +,-, ~,and,! (but not including ++or--)
  • Multiplication Operator: *,/
  • Shift operators: <<,>> and >>>
  • Relational operator: <,<=,>,>=
  • Comparison operator: ==,!=
  • Bitwise AND logical operators: &,^.|
  • Conditions and conditions or operators: &&,| |
  • Ternary operator:? :
  • An expression with parentheses, in which the contents of this parenthesis are a constant expression
  • A simple variable name that refers to a constant expression, final int x = 0; y = x;//This x is a simple variable name
  • The name of the type. Variable name, which refers to a constant expression Math.PI

Constant expressions of type string tend to be unique through the interned () method, so the string type is often interned (this does not know how to describe it)

Personal understanding, if there is an incorrect place, welcome to point out

Java constant expression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.