Metaprogramming
Java Reflection API offers functionality to introspect and reflect on class types and properties.
It is also used by Spring internally to create and manage objects.
For example, creating object without using new
keyword natively #interview-question :
public class Example {
public Example() {
System.out.println("Object created using reflection!");
}
public static void main(String[] args) {
try {
// Create an instance using reflection
Example example = Example.class.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}