A receiver parameter is an optional, explicit syntactic representation of the implicitly passedDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
this reference in a Java instance method or the enclosing instance in an inner class constructor. Introduced in Java 8 (JSR 308), it provides a formal parameter target in the method signature so that developers can apply type annotations to the object on which the method is invoked.
While the inclusion of a receiver parameter does not alter the method descriptor (signature) or invocation semantics, it does affect bytecode generation when annotated. Applying a runtime-retained type annotation to a receiver parameter causes the Java compiler to emit a RuntimeVisibleTypeAnnotations attribute into the compiled class file. This metadata is fully accessible at runtime via reflection using java.lang.reflect.Method.getAnnotatedReceiverType() or java.lang.reflect.Constructor.getAnnotatedReceiverType().
Annotation Definition Requirement
Because receiver parameters only accept type annotations, any annotation applied to them must be explicitly meta-annotated with@Target(ElementType.TYPE_USE).
Syntax in Instance Methods
In a standard instance method, the receiver parameter is declared using the exact type of the enclosing class and the exact identifierthis. If the enclosing class is generic, the parameterized type must be used.
Syntax in Inner Class Constructors
For non-static inner classes, the constructor implicitly receives a reference to the enclosing outer class instance. The receiver parameter allows this to be declared explicitly using the outer class type and the identifierOuterType.this.
Technical Constraints
When declaring a receiver parameter, the Java compiler enforces the following strict structural rules:- Position: It must be the absolute first parameter in the formal parameter list.
- Identifier: It must be named exactly
thisfor instance methods, orOuterClass.thisfor inner class constructors. Custom variable names (e.g.,Transaction<T> obj) will result in a compilation error. - Type Matching: The declared type must exactly match the class or interface in which the method is defined. It cannot be a superclass, subclass, or implemented interface. Crucially, if the enclosing class is generic (e.g.,
class Transaction<T>), the receiver parameter’s type must be the exact parameterized type, including its type arguments (e.g.,Transaction<T> this). Using a raw type (Transaction this) in a generic class results in a compilation error. - Contextual Limitation: It cannot be declared in
staticmethods. Because static methods are resolved at the class level and do not possess an instance context, there is no receiver object to represent. - Invocation: The caller does not pass an argument for the receiver parameter. The compiler automatically binds the invoking instance to this parameter, exactly as it does with the implicit
thisreference.
Master Java with Deep Grasping Methodology!Learn More





