package tp7; import java.util.ArrayList; import javax.swing.JTextField; import java.io.File; import java.lang.reflect.*; public class Ex1 { private ArrayList Liste; public Ex1 (ArrayList a) { Liste=a; } public Method[] methodesdei (int i) { Class cl = Liste.get(i).getClass(); Method[] m = cl.getMethods(); return m; } public Class superclasse() { Class ret; ArrayList cl= new ArrayList(); for (int i = 0; i < Liste.size(); i++) { cl.add(Liste.get(i).getClass()); } ArrayList cl2 = new ArrayList(); while (cl2.add(cl.get(0).getSuperclass())); Object tmp2=new Object(); ret = tmp2.getClass(); for (Class tmp : cl2) { Boolean fornow = true; for (int i = 1; i < Liste.size(); i ++) { if (!tmp.isInstance(Liste.get(i))){ fornow = false; } } if (fornow) { ret = tmp; break; } } return ret; } public void add (T obj) { Liste.add(obj); } public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(new Integer(12)); list.add(new String("allo")); list.add(new Double(12.2311)); list.add(new File(".")); list.add(new JTextField()); Ex1 test = new Ex1(list); System.out.println(test.superclasse()); } }