-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexpressions.html
More file actions
111 lines (102 loc) · 50.1 KB
/
expressions.html
File metadata and controls
111 lines (102 loc) · 50.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Java - Expressions</title>
<meta name="generator" content="VuePress 1.8.2">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="description" content="Operator Precedence, Expression evaluation order, Expression Basics, Constant Expressions">
<meta property="og:site_name" content="DevTut">
<meta property="og:title" content="Java - Expressions">
<meta property="og:description" content="Operator Precedence, Expression evaluation order, Expression Basics, Constant Expressions">
<meta property="og:type" content="article">
<meta property="og:url" content="/java/expressions.html">
<meta property="og:image" content="/logo.png">
<meta name="twitter:title" content="Java - Expressions">
<meta name="twitter:description" content="Operator Precedence, Expression evaluation order, Expression Basics, Constant Expressions">
<meta name="twitter:url" content="/java/expressions.html">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="/logo.png">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="msapplication-TileImage" content="/mstile-150x150.png">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="google-site-verification" content="76_rKXgwMVIjd-axJC_1zPV9OS4mEjvtgjYOWVkAdnQ">
<link rel="preload" href="/assets/css/0.styles.60619e34.css" as="style"><link rel="preload" href="/assets/js/app.1779e102.js" as="script"><link rel="preload" href="/assets/js/3.2cfa8016.js" as="script"><link rel="preload" href="/assets/js/1567.2011ec91.js" as="script">
<link rel="stylesheet" href="/assets/css/0.styles.60619e34.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">DevTut</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/java/" aria-current="page" class="sidebar-link">Disclaimer</a></li><li><a href="/java/java-editions-versions-releases-and-distributions.html" class="sidebar-link">Java Editions, Versions, Releases and Distributions</a></li><li><a href="/java/installing-java-standard-edition.html" class="sidebar-link">Installing Java (Standard Edition)</a></li><li><a href="/java/getting-started-with-java-language.html" class="sidebar-link">Getting started with Java Language</a></li><li><a href="/java/type-conversion.html" class="sidebar-link">Type Conversion</a></li><li><a href="/java/getters-and-setters.html" class="sidebar-link">Getters and Setters</a></li><li><a href="/java/reference-data-types.html" class="sidebar-link">Reference Data Types</a></li><li><a href="/java/java-compiler-javac.html" class="sidebar-link">Java Compiler - 'javac'</a></li><li><a href="/java/documenting-java-code.html" class="sidebar-link">Documenting Java Code</a></li><li><a href="/java/command-line-argument-processing.html" class="sidebar-link">Command line Argument Processing</a></li><li><a href="/java/the-java-command-java-and-javaw.html" class="sidebar-link">The Java Command - 'java' and 'javaw'</a></li><li><a href="/java/literals.html" class="sidebar-link">Literals</a></li><li><a href="/java/primitive-data-types.html" class="sidebar-link">Primitive Data Types</a></li><li><a href="/java/strings.html" class="sidebar-link">Strings</a></li><li><a href="/java/stringbuffer.html" class="sidebar-link">StringBuffer</a></li><li><a href="/java/stringbuilder.html" class="sidebar-link">StringBuilder</a></li><li><a href="/java/string-tokenizer.html" class="sidebar-link">String Tokenizer</a></li><li><a href="/java/splitting-a-string-into-fixed-length-parts.html" class="sidebar-link">Splitting a string into fixed length parts</a></li><li><a href="/java/date-class.html" class="sidebar-link">Date Class</a></li><li><a href="/java/dates-and-time-java-time.html" class="sidebar-link">Dates and Time (java.time.*)</a></li><li><a href="/java/localtime.html" class="sidebar-link">LocalTime</a></li><li><a href="/java/bigdecimal.html" class="sidebar-link">BigDecimal</a></li><li><a href="/java/biginteger.html" class="sidebar-link">BigInteger</a></li><li><a href="/java/numberformat.html" class="sidebar-link">NumberFormat</a></li><li><a href="/java/bit-manipulation.html" class="sidebar-link">Bit Manipulation</a></li><li><a href="/java/arrays.html" class="sidebar-link">Arrays</a></li><li><a href="/java/collections.html" class="sidebar-link">Collections</a></li><li><a href="/java/lists.html" class="sidebar-link">Lists</a></li><li><a href="/java/sets.html" class="sidebar-link">Sets</a></li><li><a href="/java/list-vs-set.html" class="sidebar-link">List vs SET</a></li><li><a href="/java/maps.html" class="sidebar-link">Maps</a></li><li><a href="/java/linkedhashmap.html" class="sidebar-link">LinkedHashMap</a></li><li><a href="/java/weakhashmap.html" class="sidebar-link">WeakHashMap</a></li><li><a href="/java/sortedmap.html" class="sidebar-link">SortedMap</a></li><li><a href="/java/treemap-and-treeset.html" class="sidebar-link">TreeMap and TreeSet</a></li><li><a href="/java/queues-and-deques.html" class="sidebar-link">Queues and Deques</a></li><li><a href="/java/dequeue-interface.html" class="sidebar-link">Dequeue Interface</a></li><li><a href="/java/enums.html" class="sidebar-link">Enums</a></li><li><a href="/java/enum-map.html" class="sidebar-link">Enum Map</a></li><li><a href="/java/enumset-class.html" class="sidebar-link">EnumSet class</a></li><li><a href="/java/enum-starting-with-number.html" class="sidebar-link">Enum starting with number</a></li><li><a href="/java/hashtable.html" class="sidebar-link">Hashtable</a></li><li><a href="/java/operators.html" class="sidebar-link">Operators</a></li><li><a href="/java/constructors.html" class="sidebar-link">Constructors</a></li><li><a href="/java/object-class-methods-and-constructor.html" class="sidebar-link">Object Class Methods and Constructor</a></li><li><a href="/java/annotations.html" class="sidebar-link">Annotations</a></li><li><a href="/java/immutable-class.html" class="sidebar-link">Immutable Class</a></li><li><a href="/java/immutable-objects.html" class="sidebar-link">Immutable Objects</a></li><li><a href="/java/visibility-controlling-access-to-members-of-a-class.html" class="sidebar-link">Visibility (controlling access to members of a class)</a></li><li><a href="/java/generics.html" class="sidebar-link">Generics</a></li><li><a href="/java/classes-and-objects.html" class="sidebar-link">Classes and Objects</a></li><li><a href="/java/local-inner-class.html" class="sidebar-link">Local Inner Class</a></li><li><a href="/java/nested-and-inner-classes.html" class="sidebar-link">Nested and Inner Classes</a></li><li><a href="/java/the-java-util-objects-class.html" class="sidebar-link">The java.util.Objects Class</a></li><li><a href="/java/default-methods.html" class="sidebar-link">Default Methods</a></li><li><a href="/java/packages.html" class="sidebar-link">Packages</a></li><li><a href="/java/inheritance.html" class="sidebar-link">Inheritance</a></li><li><a href="/java/reference-types.html" class="sidebar-link">Reference Types</a></li><li><a href="/java/console-i-o.html" class="sidebar-link">Console I/O</a></li><li><a href="/java/streams.html" class="sidebar-link">Streams</a></li><li><a href="/java/inputstreams-and-outputstreams.html" class="sidebar-link">InputStreams and OutputStreams</a></li><li><a href="/java/readers-and-writers.html" class="sidebar-link">Readers and Writers</a></li><li><a href="/java/preferences.html" class="sidebar-link">Preferences</a></li><li><a href="/java/collection-factory-methods.html" class="sidebar-link">Collection Factory Methods</a></li><li><a href="/java/alternative-collections.html" class="sidebar-link">Alternative Collections</a></li><li><a href="/java/concurrent-collections.html" class="sidebar-link">Concurrent Collections</a></li><li><a href="/java/choosing-collections.html" class="sidebar-link">Choosing Collections</a></li><li><a href="/java/super-keyword.html" class="sidebar-link">super keyword</a></li><li><a href="/java/serialization.html" class="sidebar-link">Serialization</a></li><li><a href="/java/optional.html" class="sidebar-link">Optional</a></li><li><a href="/java/object-references.html" class="sidebar-link">Object References</a></li><li><a href="/java/exceptions-and-exception-handling.html" class="sidebar-link">Exceptions and exception handling</a></li><li><a href="/java/calendar-and-its-subclasses.html" class="sidebar-link">Calendar and its Subclasses</a></li><li><a href="/java/using-the-static-keyword.html" class="sidebar-link">Using the static keyword</a></li><li><a href="/java/properties-class.html" class="sidebar-link">Properties Class</a></li><li><a href="/java/lambda-expressions.html" class="sidebar-link">Lambda Expressions</a></li><li><a href="/java/basic-control-structures.html" class="sidebar-link">Basic Control Structures</a></li><li><a href="/java/bufferedwriter.html" class="sidebar-link">BufferedWriter</a></li><li><a href="/java/new-file-i-o.html" class="sidebar-link">New File I/O</a></li><li><a href="/java/file-i-o.html" class="sidebar-link">File I/O</a></li><li><a href="/java/scanner.html" class="sidebar-link">Scanner</a></li><li><a href="/java/interfaces.html" class="sidebar-link">Interfaces</a></li><li><a href="/java/regular-expressions.html" class="sidebar-link">Regular Expressions</a></li><li><a href="/java/comparable-and-comparator.html" class="sidebar-link">Comparable and Comparator</a></li><li><a href="/java/java-floating-point-operations.html" class="sidebar-link">Java Floating Point Operations</a></li><li><a href="/java/currency-and-money.html" class="sidebar-link">Currency and Money</a></li><li><a href="/java/object-cloning.html" class="sidebar-link">Object Cloning</a></li><li><a href="/java/recursion.html" class="sidebar-link">Recursion</a></li><li><a href="/java/converting-to-and-from-strings.html" class="sidebar-link">Converting to and from Strings</a></li><li><a href="/java/random-number-generation.html" class="sidebar-link">Random Number Generation</a></li><li><a href="/java/singletons.html" class="sidebar-link">Singletons</a></li><li><a href="/java/autoboxing.html" class="sidebar-link">Autoboxing</a></li><li><a href="/java/2d-graphics-in-java.html" class="sidebar-link">2D Graphics in Java</a></li><li><a href="/java/jaxb.html" class="sidebar-link">JAXB</a></li><li><a href="/java/class-java-reflection.html" class="sidebar-link">Class - Java Reflection</a></li><li><a href="/java/networking.html" class="sidebar-link">Networking</a></li><li><a href="/java/nio-networking.html" class="sidebar-link">NIO - Networking</a></li><li><a href="/java/httpurlconnection.html" class="sidebar-link">HttpURLConnection</a></li><li><a href="/java/jax-ws.html" class="sidebar-link">JAX-WS</a></li><li><a href="/java/nashorn-javascript-engine.html" class="sidebar-link">Nashorn JavaScript engine</a></li><li><a href="/java/java-native-interface.html" class="sidebar-link">Java Native Interface</a></li><li><a href="/java/functional-interfaces.html" class="sidebar-link">Functional Interfaces</a></li><li><a href="/java/fluent-interface.html" class="sidebar-link">Fluent Interface</a></li><li><a href="/java/remote-method-invocation-rmi.html" class="sidebar-link">Remote Method Invocation (RMI)</a></li><li><a href="/java/iterator-and-iterable.html" class="sidebar-link">Iterator and Iterable</a></li><li><a href="/java/reflection-api.html" class="sidebar-link">Reflection API</a></li><li><a href="/java/bytebuffer.html" class="sidebar-link">ByteBuffer</a></li><li><a href="/java/applets.html" class="sidebar-link">Applets</a></li><li><a href="/java/expressions.html" aria-current="page" class="active sidebar-link">Expressions</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/java/expressions.html#operator-precedence" class="sidebar-link">Operator Precedence</a></li><li class="sidebar-sub-header"><a href="/java/expressions.html#expression-evaluation-order" class="sidebar-link">Expression evaluation order</a></li><li class="sidebar-sub-header"><a href="/java/expressions.html#expression-basics" class="sidebar-link">Expression Basics</a></li><li class="sidebar-sub-header"><a href="/java/expressions.html#constant-expressions" class="sidebar-link">Constant Expressions</a></li></ul></li><li><a href="/java/json-in-java.html" class="sidebar-link">JSON in Java</a></li><li><a href="/java/xml-parsing-using-the-jaxp-apis.html" class="sidebar-link">XML Parsing using the JAXP APIs</a></li><li><a href="/java/xml-xpath-evaluation.html" class="sidebar-link">XML XPath Evaluation</a></li><li><a href="/java/xom-xml-object-model.html" class="sidebar-link">XOM - XML Object Model</a></li><li><a href="/java/polymorphism.html" class="sidebar-link">Polymorphism</a></li><li><a href="/java/encapsulation.html" class="sidebar-link">Encapsulation</a></li><li><a href="/java/java-agents.html" class="sidebar-link">Java Agents</a></li><li><a href="/java/varargs-variable-argument.html" class="sidebar-link">Varargs (Variable Argument)</a></li><li><a href="/java/logging-java-util-logging.html" class="sidebar-link">Logging (java.util.logging)</a></li><li><a href="/java/log4j-log4j2.html" class="sidebar-link">log4j / log4j2</a></li><li><a href="/java/oracle-official-code-standard.html" class="sidebar-link">Oracle Official Code Standard</a></li><li><a href="/java/character-encoding.html" class="sidebar-link">Character encoding</a></li><li><a href="/java/apache-commons-lang.html" class="sidebar-link">Apache Commons Lang</a></li><li><a href="/java/localization-and-internationalization.html" class="sidebar-link">Localization and Internationalization</a></li><li><a href="/java/parallel-programming-with-fork-join-framework.html" class="sidebar-link">Parallel programming with Fork/Join framework</a></li><li><a href="/java/non-access-modifiers.html" class="sidebar-link">Non-Access Modifiers</a></li><li><a href="/java/process.html" class="sidebar-link">Process</a></li><li><a href="/java/java-native-access.html" class="sidebar-link">Java Native Access</a></li><li><a href="/java/modules.html" class="sidebar-link">Modules</a></li><li><a href="/java/concurrent-programming-threads.html" class="sidebar-link">Concurrent Programming (Threads)</a></li><li><a href="/java/executor-executorservice-and-thread-pools.html" class="sidebar-link">Executor, ExecutorService and Thread pools</a></li><li><a href="/java/threadlocal.html" class="sidebar-link">ThreadLocal</a></li><li><a href="/java/using-threadpoolexecutor-in-multithreaded-applications.html" class="sidebar-link">Using ThreadPoolExecutor in MultiThreaded applications.</a></li><li><a href="/java/common-java-pitfalls.html" class="sidebar-link">Common Java Pitfalls</a></li><li><a href="/java/java-pitfalls-exception-usage.html" class="sidebar-link">Java Pitfalls - Exception usage</a></li><li><a href="/java/java-pitfalls-language-syntax.html" class="sidebar-link">Java Pitfalls - Language syntax</a></li><li><a href="/java/java-pitfalls-threads-and-concurrency.html" class="sidebar-link">Java Pitfalls - Threads and Concurrency</a></li><li><a href="/java/java-pitfalls-nulls-and-nullpointerexception.html" class="sidebar-link">Java Pitfalls - Nulls and NullPointerException</a></li><li><a href="/java/java-pitfalls-performance-issues.html" class="sidebar-link">Java Pitfalls - Performance Issues</a></li><li><a href="/java/serviceloader.html" class="sidebar-link">ServiceLoader</a></li><li><a href="/java/classloaders.html" class="sidebar-link">Classloaders</a></li><li><a href="/java/creating-images-programmatically.html" class="sidebar-link">Creating Images Programmatically</a></li><li><a href="/java/atomic-types.html" class="sidebar-link">Atomic Types</a></li><li><a href="/java/rsa-encryption.html" class="sidebar-link">RSA Encryption</a></li><li><a href="/java/secure-objects.html" class="sidebar-link">Secure objects</a></li><li><a href="/java/security-cryptography.html" class="sidebar-link">Security & Cryptography</a></li><li><a href="/java/securitymanager.html" class="sidebar-link">SecurityManager</a></li><li><a href="/java/jndi.html" class="sidebar-link">JNDI</a></li><li><a href="/java/sun-misc-unsafe.html" class="sidebar-link">sun.misc.Unsafe</a></li><li><a href="/java/java-memory-model.html" class="sidebar-link">Java Memory Model</a></li><li><a href="/java/java-deployment.html" class="sidebar-link">Java deployment</a></li><li><a href="/java/java-plugin-system-implementations.html" class="sidebar-link">Java plugin system implementations</a></li><li><a href="/java/javabean.html" class="sidebar-link">JavaBean</a></li><li><a href="/java/java-se-7-features.html" class="sidebar-link">Java SE 7 Features</a></li><li><a href="/java/java-se-8-features.html" class="sidebar-link">Java SE 8 Features</a></li><li><a href="/java/dynamic-method-dispatch.html" class="sidebar-link">Dynamic Method Dispatch</a></li><li><a href="/java/generating-java-code.html" class="sidebar-link">Generating Java Code</a></li><li><a href="/java/jshell.html" class="sidebar-link">JShell</a></li><li><a href="/java/stack-walking-api.html" class="sidebar-link">Stack-Walking API</a></li><li><a href="/java/sockets.html" class="sidebar-link">Sockets</a></li><li><a href="/java/java-sockets.html" class="sidebar-link">Java Sockets</a></li><li><a href="/java/ftp-file-transfer-protocol.html" class="sidebar-link">FTP (File Transfer Protocol)</a></li><li><a href="/java/using-other-scripting-languages-in-java.html" class="sidebar-link">Using Other Scripting Languages in Java</a></li><li><a href="/java/c-comparison.html" class="sidebar-link">C++ Comparison</a></li><li><a href="/java/audio.html" class="sidebar-link">Audio</a></li><li><a href="/java/java-print-service.html" class="sidebar-link">Java Print Service</a></li><li><a href="/java/completablefuture.html" class="sidebar-link">CompletableFuture</a></li><li><a href="/java/runtime-commands.html" class="sidebar-link">Runtime Commands</a></li><li><a href="/java/unit-testing.html" class="sidebar-link">Unit Testing</a></li><li><a href="/java/asserting.html" class="sidebar-link">Asserting</a></li><li><a href="/java/multi-release-jar-files.html" class="sidebar-link">Multi-Release JAR Files</a></li><li><a href="/java/just-in-time-jit-compiler.html" class="sidebar-link">Just in Time (JIT) compiler</a></li><li><a href="/java/bytecode-modification.html" class="sidebar-link">Bytecode Modification</a></li><li><a href="/java/disassembling-and-decompiling.html" class="sidebar-link">Disassembling and Decompiling</a></li><li><a href="/java/jmx.html" class="sidebar-link">JMX</a></li><li><a href="/java/java-virtual-machine-jvm.html" class="sidebar-link">Java Virtual Machine (JVM)</a></li><li><a href="/java/xjc.html" class="sidebar-link">XJC</a></li><li><a href="/java/jvm-flags.html" class="sidebar-link">JVM Flags</a></li><li><a href="/java/jvm-tool-interface.html" class="sidebar-link">JVM Tool Interface</a></li><li><a href="/java/java-memory-management.html" class="sidebar-link">Java Memory Management</a></li><li><a href="/java/java-performance-tuning.html" class="sidebar-link">Java Performance Tuning</a></li><li><a href="/java/benchmarks.html" class="sidebar-link">Benchmarks</a></li><li><a href="/java/fileupload-to-aws.html" class="sidebar-link">FileUpload to AWS</a></li><li><a href="/java/appdynamics-and-tibco-businessworks-instrumentation-for-easy-integration.html" class="sidebar-link">AppDynamics and TIBCO BusinessWorks Instrumentation for Easy Integration</a></li><li><a href="/java/the-classpath.html" class="sidebar-link">The Classpath</a></li><li><a href="/java/resources-on-classpath.html" class="sidebar-link">Resources (on classpath)</a></li><li><a href="/java/contributors.html" class="sidebar-link">The Contributors</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="expressions"><a href="#expressions" class="header-anchor">#</a> Expressions</h1> <h2 id="operator-precedence"><a href="#operator-precedence" class="header-anchor">#</a> Operator Precedence</h2> <p>When an expression contains multiple operators, it can potentially be read in different ways. For example, the mathematical expression <code>1 + 2 x 3</code> could be read in two ways:</p> <ol><li>Add <code>1</code> and <code>2</code> and multiply the result by <code>3</code>. This gives the answer <code>9</code>. If we added parentheses, this would look like <code>( 1 + 2 ) x 3</code>.</li> <li>Add <code>1</code> to the result of multiplying <code>2</code> and <code>3</code>. This gives the answer <code>7</code>. If we added parentheses, this would look like <code>1 + ( 2 x 3 )</code>.</li></ol> <p>In mathematics, the convention is to read the expression the second way. The general rule is that multiplication and division are done before addition and subtraction. When more advanced mathematical notation is used, either the meaning is either "self-evident" (to a trained mathematician!), or parentheses are added to disambiguate. In either case, the effectiveness of the notation to convey meaning depends on the intelligence and shared knowledge of the mathematicians.</p> <p>Java has the same clear rules on how to read an expression, based on the <strong>precedence</strong> of the operators that are used.</p> <p>In general, each operator is ascribed a <strong>precedence</strong> value; see the table below.</p> <p>For example:</p> <div class="language- extra-class"><pre class="language-text"><code>
1 + 2 * 3
</code></pre></div><p>The precedence of <code>+</code> is lower than the precedence of <code>*</code>, so the result of the expression is 7, not 9.</p> <table><thead><tr><th>Description</th> <th>Operators / constructs (primary)</th> <th>Precedence</th> <th>Associativity</th></tr></thead> <tbody><tr><td>Qualifier<br>Parentheses<br>Instance creation<br>Field access<br>Array access<br>Method invocation<br>Method reference</td> <td>name<code>.</code>name<br><code>(</code>expr<code>)</code><br><code>new</code><br>primary<code>.</code>name<br>primary<code>[</code>expr<code>]</code><br>primary<code>(</code>expr, ...<code>)</code><br>primary<code>::</code>name</td> <td>15</td> <td>Left to right</td></tr> <tr><td>Post increment</td> <td>expr<code>++</code>, expr<code>--</code></td> <td>14</td> <td>-</td></tr> <tr><td>Pre increment<br>Unary<br>Cast<sup>1</sup></td> <td><code>++</code>expr, <code>--</code>expr,<br><code>+</code>expr, <code>-</code>expr, <code>~</code>expr, <code>!</code>expr,<br><code>(</code>type<code>)</code>expr</td> <td>13</td> <td>-<br>Right to left<br>Right to left</td></tr> <tr><td>Multiplicative</td> <td>* / %</td> <td>12</td> <td>Left to right</td></tr> <tr><td>Additive</td> <td>+ -</td> <td>11</td> <td>Left to right</td></tr> <tr><td>Shift</td> <td><< >> >>></td> <td>10</td> <td>Left to right</td></tr> <tr><td>Relational</td> <td>< > <= >= <code>instanceof</code></td> <td>9</td> <td>Left to right</td></tr> <tr><td>Equality</td> <td>== !=</td> <td>8</td> <td>Left to right</td></tr> <tr><td>Bitwise AND</td> <td>&</td> <td>7</td> <td>Left to right</td></tr> <tr><td>Bitwise exclusive OR</td> <td>^</td> <td>6</td> <td>Left to right</td></tr> <tr><td>Bitwise inclusive OR</td> <td></td> <td></td> <td>5</td></tr> <tr><td>Logical AND</td> <td>&&</td> <td>4</td> <td>Left to right</td></tr> <tr><td>Logical OR</td> <td></td> <td></td> <td></td></tr> <tr><td>Conditional<sup>1</sup></td> <td>? :</td> <td>2</td> <td>Right to left</td></tr> <tr><td>Assignment<br>Lambda<sup>1</sup></td> <td>= *= /= %= += -= <<= >>= >>>= &= ^=</td> <td>=<br>-></td> <td>1</td></tr></tbody></table> <p><sup>1</sup> Lambda expression precedence is complex, as it can also occur after a cast, or as the third part of the conditional ternary operator.</p> <h2 id="expression-evaluation-order"><a href="#expression-evaluation-order" class="header-anchor">#</a> Expression evaluation order</h2> <p>Java expressions are evaluated following the following rules:</p> <ul><li>Operands are evaluated from left to right.</li> <li>The operands of an operator are evaluated before the operator.</li> <li>Operators are evaluated according to operator precedence</li> <li>Argument lists are evaluated from left to right.</li></ul> <h3 id="simple-example"><a href="#simple-example" class="header-anchor">#</a> Simple Example</h3> <p>In the following example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token function">method1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token function">method2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>the order of evaluation is:</p> <ol><li>The left operand of <code>=</code> operator is evaluated to the address of <code>i</code>.</li> <li>The left operand of the <code>+</code> operator (<code>method1()</code>) is evaluated.</li> <li>The right operand of the <code>+</code> operator (<code>method2()</code>) is evaluated.</li> <li>The <code>+</code> operation is evaluated.</li> <li>The <code>=</code> operation is evaluated, assigning the result of the addition to <code>i</code>.</li></ol> <p>Note that if the effects of the calls are observable, you will be able to observe that the call to <code>method1</code> occurs before the call to <code>method2</code>.</p> <h3 id="example-with-an-operator-which-has-a-side-effect"><a href="#example-with-an-operator-which-has-a-side-effect" class="header-anchor">#</a> Example with an operator which has a side-effect</h3> <p>In the following example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
intArray<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token operator">++</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre></div><p>the order of evaluation is:</p> <ol><li>The left operand of <code>=</code> operator is evaluated. This gives the address of <code>intArray[1]</code>.</li> <li>The pre-increment is evaluated. This adds <code>1</code> to <code>i</code>, and evaluates to <code>2</code>.</li> <li>The right hand operand of the <code>+</code> is evaluated.</li> <li>The <code>+</code> operation is evaluated to: <code>2 + 1</code> -> <code>3</code>.</li> <li>The <code>=</code> operation is evaluated, assigning <code>3</code> to <code>intArray[1]</code>.</li></ol> <p>Note that since the left-hand operand of the <code>=</code> is evaluated first, it is not influenced by the side-effect of the <code>++i</code> subexpression.</p> <p>Reference:</p> <ul><li><a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.7" target="_blank" rel="noopener noreferrer">JLS 15.7 - Evaluation Order<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="expression-basics"><a href="#expression-basics" class="header-anchor">#</a> Expression Basics</h2> <p>Expressions in Java are the primary construct for doing calculations. Here are some examples:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token number">1</span> <span class="token comment">// A simple literal is an expression</span>
<span class="token number">1</span> <span class="token operator">+</span> <span class="token number">2</span> <span class="token comment">// A simple expression that adds two numbers</span>
<span class="token punctuation">(</span>i <span class="token operator">+</span> j<span class="token punctuation">)</span> <span class="token operator">/</span> k <span class="token comment">// An expression with multiple operations</span>
<span class="token punctuation">(</span>flag<span class="token punctuation">)</span> <span class="token operator">?</span> c <span class="token operator">:</span> d <span class="token comment">// An expression using the "conditional" operator</span>
<span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">)</span> s <span class="token comment">// A type-cast is an expression</span>
obj<span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// A method call is an expression</span>
<span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Creation of an object is an expression</span>
<span class="token keyword">new</span> <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token comment">// Creation of an object is an expression</span>
</code></pre></div><p>In general, an expression consists of the following forms:</p> <li>Expression names which consist of:
<ul>
- Simple identifiers; e.g. `someIdentifier`
- Qualified identifiers; e.g. `MyClass.someField`
<ul><li>Literals; e.g. <code>1</code>, <code>1.0</code>, <code>'X'</code>, <code>"hello"</code>, <code>false</code> and <code>null</code></li> <li>Class literal expressions; e.g. <code>MyClass.class</code></li> <li><code>this</code> and <code><TypeName> . this</code></li> <li>Parenthesized expressions; e.g. <code>( a + b )</code></li> <li>Class instance creation expressions; e.g. <code>new MyClass(1, 2, 3)</code></li> <li>Array instance creation expressions; e.g. <code>new int[3]</code></li> <li>Field access expressions; e.g. <code>obj.someField</code> or <code>this.someField</code></li> <li>Array access expressions; e.g. <code>vector[21]</code></li> <li>Method invocations; e.g. <code>obj.doIt(1, 2, 3)</code></li> <li>Method references (Java 8 and later); e.g. <code>MyClass::doIt</code></li></ul> <p>The details of the different forms of expressions may be found in other Topics.</p> <ul><li>The <a href="http://stackoverflow.com/documentation/java/176/operators" target="_blank" rel="noopener noreferrer">Operators<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> topic covers unary, binary and ternary operator expressions.</li> <li>The <a href="http://stackoverflow.com/documentation/java/91/lambda-expressions#t=20161216024035664514" target="_blank" rel="noopener noreferrer">Lambda expressions<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> topic covers lambda expressions and method reference expressions.</li> <li>The <a href="http://stackoverflow.com/documentation/java/114/classes-and-objects#t=201612160817408962117" target="_blank" rel="noopener noreferrer">Classes and Objects<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> topic covers class instance creation expressions.</li> <li>The <a href="http://stackoverflow.com/documentation/java/99/arrays#t=201612160241346240996" target="_blank" rel="noopener noreferrer">Arrays<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> topic covers array access expressions and array instance creation expressions.</li> <li>The <a href="http://stackoverflow.com/documentation/java/8250/literals#t=201612190020004937953" target="_blank" rel="noopener noreferrer">Literals<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> topic covers the different kinds of literals expressions.</li></ul> <h3 id="the-type-of-an-expression"><a href="#the-type-of-an-expression" class="header-anchor">#</a> The Type of an Expression</h3> <p>In most cases, an expression has a static type that can be determined at compile time by examining and its subexpressions. These are referred to as <strong>stand-alone</strong> expressions.</p> <p>However, (in Java 8 and later) the following kinds of expressions may be <strong>poly expressions</strong>:</p> <ul><li>Parenthesized expressions</li> <li>Class instance creation expressions</li> <li>Method invocation expressions</li> <li>Method reference expressions</li> <li>Conditional expressions</li> <li>Lambda expressions</li></ul> <p>When an expression is a poly expression, its type may be influenced by the expression's <strong>target type</strong>; i.e. what it is being used for.</p> <h3 id="the-value-of-an-expression"><a href="#the-value-of-an-expression" class="header-anchor">#</a> The value of an Expression</h3> <p>The value of an expression is assignment compatible with its type. The exception to this is when <strong>heap pollution</strong> has occurred; e.g. because "unsafe conversion" warnings have been (inappropriately) suppressed or ignored.</p> <h3 id="expression-statements"><a href="#expression-statements" class="header-anchor">#</a> Expression Statements</h3> <p>Unlike many other languages, Java does not generally allow expressions to be used as statements. For example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">compute</span><span class="token punctuation">(</span><span class="token keyword">int</span> i<span class="token punctuation">,</span> <span class="token keyword">int</span> j<span class="token punctuation">)</span> <span class="token punctuation">{</span>
i <span class="token operator">+</span> j<span class="token punctuation">;</span> <span class="token comment">// ERROR</span>
<span class="token punctuation">}</span>
</code></pre></div><p>Since the result of evaluating an expression like cannot be use, and since it cannot affect the execution of the program in any other way, the Java designers took the position that such usage is either a mistake, or misguided.</p> <p>However, this does not apply to all expressions. A subset of expressions are (in fact) legal as statements. The set comprises:</p> <ul><li>Assignment expression, including <strong>operation-and-becomes</strong> assignments.</li> <li>Pre and post increment and decrement expressions.</li> <li>Method calls (<code>void</code> or non-<code>void</code>).</li> <li>Class instance creation expressions.</li></ul> <h2 id="constant-expressions"><a href="#constant-expressions" class="header-anchor">#</a> Constant Expressions</h2> <p>A constant expression is an expression that yields a primitive type or a String, and whose value can be evaluated at compile time to a literal. The expression must evaluate without throwing an exception, and it must be composed of only the following:</p> <li>
Primitive and String literals.
</li> <li>
Type casts to primitive types or `String`.
</li> <li>
The following unary operators: `+`, `-`, `~` and `!`.
</li> <li>
The following binary operators: `*`, `/`, `%`, `+`, `-`, `<<`, `>>`, `>>>`, `<`, `<=`, `>`, `>=`, `==`, `!=`, `&`, `^`, `|`, `&&` and `||`.
</li> <li>
The ternary conditional operator `?` `:`.
</li> <li>
Parenthesized constant expressions.
</li> <li>
Simple names that refer to constant variables. (A constant variable is a variable declared as `final` where the initializer expression is itself a constant expression.)
</li> <li>
Qualified names of the form `<TypeName> . <Identifier>` that refer to constant variables.
</Identifier></TypeName></li> <p>Note that the above list <strong>excludes</strong> <code>++</code> and <code>--</code>, the assignment operators, <code>class</code> and <code>instanceof</code>, method calls and references to general variables or fields.</p> <p>Constant expressions of type <code>String</code> result in an "interned" <code>String</code>, and floating point operations in constant expressions are evaluated with FP-strict semantics.</p> <h3 id="uses-for-constant-expressions"><a href="#uses-for-constant-expressions" class="header-anchor">#</a> Uses for Constant Expressions</h3> <p>Constant expressions can be used (just about) anywhere that a normal expression can be used. However, they have a special significance in the following contexts.</p> <p>Constant expressions are required for case labels in switch statements. For example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">switch</span> <span class="token punctuation">(</span>someValue<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">case</span> <span class="token number">1</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token operator">:</span> <span class="token comment">// OK</span>
<span class="token keyword">case</span> <span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token comment">// Error - not a constant expression</span>
<span class="token function">doSomething</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><p>When the expression on the right hand side of an assignment is a constant expression, then the assignment can perform a primitive narrowing conversion. This is allowed provided that the value of the constant expression is within the range of the type on the left hand side. (See <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.3" target="_blank" rel="noopener noreferrer">JLS 5.1.3<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> and <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.2" target="_blank" rel="noopener noreferrer">5.2<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>) For example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">byte</span> b1 <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// OK - primitive narrowing conversion.</span>
<span class="token keyword">byte</span> b2 <span class="token operator">=</span> <span class="token number">127</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// Error - out of range</span>
<span class="token keyword">byte</span> b3 <span class="token operator">=</span> b1 <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// Error - not a constant expession</span>
<span class="token keyword">byte</span> b4 <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">byte</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>b1 <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// OK</span>
</code></pre></div><p>When a constant expression is used as the condition in a <code>do</code>, <code>while</code> or <code>for</code>, then it affects the readability analysis. For example:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token function">doSomething</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Error - statenent not reachable</span>
<span class="token punctuation">}</span>
<span class="token keyword">boolean</span> flag <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token keyword">while</span> <span class="token punctuation">(</span>flag<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token function">doSomething</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// OK</span>
<span class="token punctuation">}</span>
</code></pre></div><p>(Note that this does not apply <code>if</code> statements. The Java compiler allows the <code>then</code> or <code>else</code> block of an <code>if</code> statement to be unreachable. This is the Java analog of conditional compilation in C and C++.)</p> <p>Finally, <code>static final</code> fields in an class or interface with constant expression initializers are initialized eagerly. Thus, it is guaranteed that these constants will be observed in the initialized state, even when there is a cycle in the class initialization dependency graph.</p> <p>For more information, refer to <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.3" target="_blank" rel="noopener noreferrer">JLS 15.28. Constant Expressions<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <h4 id="remarks"><a href="#remarks" class="header-anchor">#</a> Remarks</h4> <p>For a reference on the operators that can be used in expressions, see <a href="http://stackoverflow.com/documentation/java/176/operators" target="_blank" rel="noopener noreferrer">Operators<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p></ul></li></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/devtut/generate/edit/master/docs/java/expressions.md" target="_blank" rel="noopener noreferrer">Edit this page on GitHub</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/java/applets.html" class="prev">
Applets
</a></span> <span class="next"><a href="/java/json-in-java.html">
JSON in Java
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.1779e102.js" defer></script><script src="/assets/js/3.2cfa8016.js" defer></script><script src="/assets/js/1567.2011ec91.js" defer></script>
</body>
</html>