// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class ReflDemo {
	public abstract static class P {
	}
	public static class CI extends P {
		private int v;
		public CI(int v) {
			this.v = v;
		}
		@Override
		public String toString() {
			return String.format("CI(%d)", v);
		}
	}
	public static class CS extends P {
		private String v;
		public CS(String v) {
			this.v = v;
		}
		@Override
		public String toString() {
			return String.format("CS(%s)", v);
		}
	}
	public static void analyze(Object o) {
		Class<?> clz = o.getClass();
		System.out.printf("class name = %s\n", clz.getName());
		System.out.printf("is array = %s\n", clz.isArray());
		if(clz.isArray()) {
			System.out.printf("element type = %s\n", clz.getComponentType().getName());
		}
		System.out.printf("is enum = %s\n", clz.isEnum());
		System.out.printf("====\n");
	}
	public static void main(String[] args) {
		analyze(123);
		analyze("ABC");
		analyze(new int[] { 123, 456 });
		analyze(new String[] { "ABC", "DEF" });
		analyze(new CI(123));
		analyze(new CS("ABC"));
		CI[] cia = { new CI(123), new CI(456) };
		analyze(cia);
		CS[] csa = { new CS("ABC"), new CS("DEF") };
		analyze(csa);
	}
}
