'Java Reflection'에 해당되는 글 1건

  1. 2009.02.19 Java Reflection

Java Reflection

Development/Java 2009. 2. 19. 21:43
Trail: The Reflection API: Table of Contents
http://java.sun.com/docs/books/tutorial/reflect/TOC.html

Summary: Loading class, Instantiate an object, Invoking method
// Loading class
URLClassLoader urlClassLoader = new URLClassLoader(new URL[], file.toURL());
Class sClass = urlClassLoader.loadClass("ClassName");

// Instantiate an object
SpecificObjectType obj = sClass.newInstance();

// Invoking method
//do something: return type of "MethodName" is String in this example
Method method = sClass.getMethod("MethodName", args types ...);
result = (String) method.invoke(obj, args...);
Posted by zennken
1

zennken

달력