Master annotations for metadata, reflection for runtime inspection, and inner classes for encapsulation.
Learn advanced Java features for metadata, introspection, and nested types.
@Override - method overrides superclass method@Deprecated - marks element as deprecated@SuppressWarnings - suppress compiler warnings@FunctionalInterface - single abstract method interface@interface MyAnnotation { String value(); }@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)--- Built-in Annotations ---
Using @Override on toString()
Dog says: Woof!
--- Custom Annotation ---
Method has @Info annotation
Author: John Doe
Version: 1.0
@interface MyAnnotation { String value(); }@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)String version() default "1.0";Review feedback below
Class<?> clazz = MyClass.class;Class<?> clazz = obj.getClass();Class<?> clazz = Class.forName("MyClass");clazz.getDeclaredFields() - all fieldsclazz.getDeclaredMethods() - all methodsclazz.getConstructors() - constructorsclazz.getDeclaredConstructor().newInstance()method.invoke(object, args)--- Class Information ---
Class name: Person
Fields: name age
Methods: getName setName getAge setAge greet
--- Create Instance ---
Created: Person[name=John, age=25]
--- Invoke Method ---
Hello, my name is John!
Class<?> c = MyClass.class;c.getDeclaredFields()c.getDeclaredMethods()c.getConstructor(types).newInstance(args)method.invoke(object, args)Review feedback below
outer.new Inner()new Outer.StaticNested()--- Member Inner Class ---
Inner class accessing outer: Hello from Outer
Inner value: 10
--- Static Nested Class ---
Static nested class value: 42
--- Local Inner Class ---
Local class says: Hello Local!
--- Anonymous Inner Class ---
Anonymous greeting: Hello World!
class Outer { class Inner { } }Outer.Inner i = outer.new Inner();new Outer.StaticNested();new Interface() { @Override... };Review feedback below