~/ learn/ java-from-zero/ cards/ Reflection basics: Class<?>, getDeclaredFields, and reading annotations at runtime
1 of 4

Type the three ways to get a Class<?> object

Type the three ways to get a Class<?> object

Answer

Class<?> c1 = obj.getClass(); Class<String> c2 = String.class; Class<?> c3 = Class.forName("com.acme.Foo");

getClass() requires a live instance. .class is a compile-time literal — preferred when the type is known. Class.forName() takes a string and throws checked ClassNotFoundException.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF