1 import java
.lang
.reflect
.Field
;
2 import java
.lang
.reflect
.Method
;
3 import java
.lang
.reflect
.Constructor
;
4 import java
.lang
.reflect
.InvocationTargetException
;
5 import java
.util
.Scanner
;
6 import java
.io
.IOException
;
10 private static void main_orig(String
[] args
) {
11 Entiers integer
= new Entiers(5);
31 integer
.supprimer(12);
34 System
.out
.println("Current size " + integer
.getCurrentSize());
39 System
.out
.println("Current size " + integer
.getCurrentSize());
43 private static void main_A(String
[] args
) {
44 if (args
.length
== 0) {
45 System
.out
.println("Please run with java Main <class name to inspect>");
48 String className
= args
[0];
52 cl
= Class
.forName(className
);
54 catch (ClassNotFoundException e
) {
55 System
.out
.println("Entered class name do not exist.");
59 Field
[] fields
= cl
.getFields();
60 Method
[] methods
= cl
.getMethods();
62 for (int i
= 0; i
< fields
.length
; i
++) {
63 System
.out
.println(fields
[i
]);
66 for (int i
= 0; i
< methods
.length
; i
++) {
67 System
.out
.println(methods
[i
]);
73 * @param String[] args main() function arguments array
75 public static void main(String
[] args
) {
76 String name
= Entiers
.class.getName();
80 cl
= Class
.forName(name
);
81 Class
[] types
= new Class
[]{Integer
.class};
82 Constructor ct
= cl
.getConstructor(types
);
83 o
= ct
.newInstance(new Integer(100));
85 catch (ClassNotFoundException e
) {
86 System
.out
.println("Class name do not exist.");
89 catch (NoSuchMethodException e
) {
92 catch (InstantiationException e
) {
95 catch (IllegalAccessException e
) {
98 catch (InvocationTargetException e
) {
102 Scanner uInput
= null;
104 uInput
= new Scanner(System
.in
);
105 System
.out
.println("Saisir le nom de la methode à invoquer:");
106 String method
= uInput
.next();
107 //TODO: one can build the input list from the method arguments list and types
108 System
.out
.println("Saisir l'argument entier paramètre de la méthode:");
109 int integer
= uInput
.nextInt();
110 Method m
= cl
.getMethod(method
, new Class
[]{Integer
.class});
111 m
.invoke(o
, integer
);
113 catch (Exception e
) {
114 System
.out
.println("Erreur:");
119 Method mDisplay
= cl
.getMethod("afficher");
122 catch (NoSuchMethodException e
) {
125 catch (IllegalAccessException e
) {
128 catch (InvocationTargetException e
) {