# 정의
Reflection is a way to invoke methods of objects on the fly (At run-time).
Reflection is the ability, at runtime, to actually create objects of classes, invoke methods, manipulate meta data.
#
- Reflection is available in most important languages (java, C# etc)
- Reflection is slow and complicated
- A method call via reflection may take 10X longer than usual
# code
import java.util.ArrayList;
public class Main {
public static void main(String[] args)
throws InstantiationException, IllegalAccessException,
ClassNotFoundException
{
ArrayList<String> al = new ArrayList<>();
ArrayList<String> onTheFlyList =
(ArrayList)
(Class.forName("java.util.ArrayList").newInstance());
onTheFlyList.add("a");
onTheFlyList.add("b");
for (String string : onTheFlyList) {
System.out.println(string);
}
}
}
댓글 영역