I have developed simpl开发者_Python百科e console based application thats a vehicle inventory.. in this application there is
one vehicle.java --> its a abstract base class
-->that contain some common attribute for vehicle (get/set)
one car.java--->it extends vehicle.java
--->that contain some car specific attribute
one bike.java--->it extends vehicle.java
--->that contain some bike specific attirbute
and one common class that contain some functions like getMaxSpeedOfVehicle, getAverageSpeed(), etc.....
This is my application basic structure . Now, i want to use reflection API, So, how can i implement reflection in my application What i have to consider for using this reflection ......?
Try this:
import java.lang.reflect.*;
public class ReflectionTeste {
public static void main(String args[]) {
try {
Class c = Class.forName( "java.lang.String" );
Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++) {
Object retobj = meth.invoke(m, arglist);
System.out.println( m[i].toString() );
}
} catch (Throwable e) {
System.err.println(e);
}
}
}
精彩评论