3 << 2L - 1
(3L << 2) - 1
10 < 12 == 6 > 17
10 << 12 == 6 >> 17
13.5e-1 % Float.POSITIVE_INFINITY
Float.POSITIVE_INFINITY + Double.NEGATIVE_INFINITY
Double.POSITIVE_INFINITY - Float.NEGATIVE_INFINITY
0.0 / -0.0 == -0.0 / 0.0
Integer.MAX_VALUE + Integer.MIN_VALUE
Long.MAX_VALUE + 5
(short) 5 * (byte) 10
(i < 15? 1.72e3f : 0)
i++ + i++ + --i // i = 3 at start
9.6. Member Access
You use the dot (.) operatoras in ref.method()to access both instance members or static members of
types. Because types can inherit members from their supertypes, there are rules regarding which member is
accessed in any given situation. Most of these rules were covered in detail in Chapter 2 and Chapter 3, but we
briefly recap them.
You access static members by using either the type name or an object reference. When you use a type name,
the member referred to is the member declared in that type (or inherited by it if there was no declaration in
that type). When you use an object reference, the declared type of the reference determines which member is
accessed, not the type of the object being referred to. Within a class, reference to a static member always
refers to the member declared in, or inherited by, that class.
Non-static members are accessed through an object referenceeither an explicit reference or implicitly this
(or one of the enclosing objects) if the non-static member is a member of the current object (or enclosing
object). Fields and nested types are accessed based on the declared type of the object reference. Similarly,
within a method, a reference to a field or nested type always refers to the declaration within that class or else
the inherited declaration. In contrast, methods are accessed based on the class of the object being referred to.
Further, the existence of method overloading means that the system has to determine which method to invoke
based on the compile-time type of the arguments used in the invocation; this process is described in detail in
the next section. The only operator that can be applied to a method member is the method invocation operator
().
You will get a NullPointerException if you use. on a reference with the value null, unless you are
accessing a static member. In that case the value of the reference is never considered, because only the type of
the reference determines the class in which to locate the member.
9.6.1. Finding the Right Method
For an invocation of a method to be correct, you must provide arguments of the proper number and type so
that exactly one matching method can be found in the class. If a method is not overloaded, determining the
correct method is simple, because only one parameter count is associated with the method name. When
overloaded methods are involved choosing the correct method is more complex. The compiler uses a "most
specific" algorithm to do the match, the general form of which is as follows:
Determine which class or interface to search for the method. Exactly how this is done depends on the
form of the method invocation. For example, if the invocation is of a static method using a class
namesuch as Math.expthen the class to search for exp is Math. On the other hand, if the method
name is not qualified in any waysuch as exp(n)then there must be a method by that name in scope