
{filelink=4674}
import java.lang.reflect.Array;
public class Comparaison_Type
{
public static void main (String[] args)
{
Integer tab1[]= {1, 2, 3, 4, 5, 5};
int tab2[]= {-1, -2, 3, -4, 5};
Integer tab3[][]= {{1, 2, 3},{4, 5, 6}};
Integer tab4[]={5,8};
System.out.println ("Tab1 a le même Type que Tab2? "+comparerType(tab1, tab2)); //false
System.out.println ("Tab1 a le même Type que Tab3? "+comparerType(tab1, tab3)); //false
System.out.println ("Tab1 a le même Type que Tab4? "+comparerType(tab1, tab4)); //true
}
/* Cette fonction retourne 'true' si
* deux tableau sont de même type
*/
public static boolean comparerType(Object array1, Object array2)
{
if (array1 == null || array2 == null) {
throw new IllegalArgumentException("Null pointeur Exception");
}
return array1.getClass().getName().equals(array2.getClass().getName());
}
}