Dynamic Proxies in Java
A dynamic proxy implements an interface at runtime and routes every call through one handler, which is how cross cutting behaviour is added.
The core language and standard library.
12 notes tagged
A dynamic proxy implements an interface at runtime and routes every call through one handler, which is how cross cutting behaviour is added.
Reflection inspects and manipulates classes at runtime. It powers most frameworks and should be rare in application code.
Wrapper classes turn primitives into objects so they can be used with generics and collections, and the conversion is automatic but not free.
An annotation attaches metadata to code. It changes nothing by itself; a compiler, a tool or a framework reads it and acts.
A record declares an immutable data carrier, and the compiler generates the constructor, accessors, equals, hashCode and toString.
An enum is a class with a fixed set of instances, which makes an invalid value impossible rather than merely unlikely.
A class declared inside another can be static, inner, local or anonymous, and the difference is mainly what each one can see.
Packages give classes a unique name and a visibility boundary, and imports simply save you from writing that full name every time.
instanceof tests the runtime type, and since Java 16 it can bind a typed variable in the same step.
final means cannot be reassigned, cannot be overridden or cannot be extended, depending on where it is written.
Two objects that are equal must have the same hash code. Breaking that contract quietly breaks every hash based collection.
Every class inherits from Object, which is where toString, equals, hashCode and getClass come from.