Throwable.getSuppressed() — suppressed exceptions
Call `getSuppressed()` on the primary exception to inspect attached exceptions, such as a resource-closing failure that occurred after the `try` body failed.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Call `getSuppressed()` on the primary exception to inspect attached exceptions, such as a resource-closing failure that occurred after the `try` body failed.
In Java, + adds numbers or concatenates text when at least one operand has type String. Operand types, numeric promotion, and parentheses determine the result. Unary + preserves the value after type promotion.
The += operator adds a value to a variable or appends text to a String and stores the result, including an implicit conversion to the variable's type.
The expression array[index] selects an array element for reading or writing. Indices start at zero, and Java checks their bounds at run time.
The `=` operator stores a value in a variable; it does not test equality. It requires compatible types, and the assignment expression itself also produces a value, allowing assignments to be chained.
The & operator preserves bits that are 1 in both integral operands. Use it to mask values and test flags. With boolean values, it means AND without short-circuit evaluation.
The &= operator stores an AND result in its left operand: bitwise for integral values, logical for boolean values.
The unary ~ operator flips every bit of an integral value after numeric promotion. Its result has type int or long. It is not the logical complement operator !: ~ does not accept boolean values.
The | operator combines corresponding integer bits: a result bit is 1 when at least one input bit is 1. With boolean operands, it performs logical OR without short-circuiting.
The |= operator combines a variable’s value with the right operand using OR and stores the result. It supports integral and boolean values.
The ^ operator applies XOR to corresponding bits of integral values. For boolean values, it tests whether they differ.
The ^= operator stores an XOR result in its left operand. It works with integral types and boolean; it does not mean exponentiation.
The (type) operator explicitly converts a value to a specified type. Numeric casts can lose data, and reference casts can throw ClassCastException; they do not change an object's class.
The ?: operator selects one of two values based on a condition. It is an expression with three operands; only the selected branch is evaluated at run time.
The -- operator subtracts 1 and stores the result in a variable. The x-- form yields the previous value, whereas --x yields the new value. Both forms update the variable while evaluating the expression.
The / operator computes a quotient. Operand types determine whether division is integer or floating-point, affecting fractional results and the behavior of division by zero.
The /= operator divides a variable’s saved value by the right operand and stores the result back, with an implicit conversion to the variable’s type.
The == operator returns boolean: it compares primitive values or reference identity. For String objects it does not compare contents; use equals for that.
The >= operator compares numeric values and returns boolean. It includes equality, making it useful for checking thresholds that include the boundary value.
The > operator checks whether the left operand is strictly greater than the right and returns boolean. Equal values produce false. It operates on numeric values after numeric promotion; a comparison involving NaN always produces false.
The ++ operator adds 1 to a variable's value. Prefix ++count produces the new value, while postfix count++ produces the previous value; both store the result in the variable.
The != operator returns boolean: it compares numeric or boolean values, while for references it tests object identity rather than contents.
The instanceof operator tests an object's compatibility with a type and returns boolean. A type pattern can also declare a variable available wherever the compiler can prove that matching succeeded. For null, the result is false.
The -> symbol separates a lambda's parameters from its body. A lambda describes behavior for a functional interface; its body executes when the appropriate method is called, not when the lambda is assigned.