// 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) 
package april;

import java.util.ArrayList;
import java.util.List;

public class ToWarnOrNotToWarn {
	private static String test1(Object o) {
		try {
			return (String)o;
		} catch(ClassCastException ex) {
			System.out.println(o.getClass().getName() + " is not a String");
			return null;
		}
	}
	private static List<String> test2(Object o) {
		try {
			return (List<String>)o;
		} catch(ClassCastException ex) {
			System.out.println(o.getClass().getName() + " is not a List<String>");
			return null;
		}
	}
	public static void main(String[] args) {
		Object o1 = "ABC";
		System.out.println(test1(o1));
		Object o2 = 123;
		System.out.println(test1(o2));
		System.out.println(test2(true));
		List<String> a1 = new ArrayList<String>();
		a1.add("ABC");
		System.out.println(test2(a1));
		System.out.println(test2(a1).get(0).substring(0, 1));
		List<Integer> a2 = new ArrayList<Integer>();
		a2.add(123);
		System.out.println(test2(a2));
		System.out.println(test2(a2).get(0).substring(0, 1));
	}
}
