import java.awt.Color;
import java.lang.reflect.*;
import java.util.Hashtable;

/**
 * A simple example that uses reflection
 *
 * @author  Computer Science Deprtment, James Madison University
 * @version 1.0
 */
public class Example2
{
    /**
     * The entry point
     *
     * @param args   The command-line arguments
     */
    public static void main(String[] args)
    {
       Object[]      list;


       list    = new Object[3];
       list[0] = new String("Fred");
       list[1] = new Hashtable();
       list[2] = new Color(255, 0, 0);

       handleList(list);
    }



    /**
     * Handle a generic list of objects
     *
     * @param  list   The list of objects
     */
    public static void handleList(Object[] list)
    {
       Class    c, colorClass, stringClass;
       int      i;

       try 
       {
          colorClass  = Class.forName("java.awt.Color");
          stringClass = Class.forName("java.lang.String"); 

          for (i=0; i < list.length; i++) 
          {
             c = list[i].getClass();
             if (c.equals(colorClass)) 
             {
                System.out.println("Handling a Color.");
             } 
             else if  (c.equals(stringClass)) 
             {
                System.out.println("Handling a String");
             } 
             else 
             {
                System.out.println("I don't know what to do.");
             }
          }
       } 
       catch (ClassNotFoundException cnfe)
       {
          System.out.println("Big trouble!");
       }
    }
}
    
