All pastes #220751 Raw Edit

Someone

public java v1 · immutable
#220751 ·published 2006-10-25 09:36 UTC
rendered paste body
import java.util.*;class ListFactory{	public static <T extends Object> List<T> create(T... o)	{		List<T> ret = new ArrayList<T>(o.length);		for (T a : o)			ret.add(a);		return ret;	}	// Can't overload this function.	public static <T extends Object> T[] createArray(T[] base, T... o)	{		List<T> ret = create(o);		return ret.toArray(base);	}}class Base {}class Child extends Base {}public class Test{	public static void test(Integer[] foo)	{}	public static void main(String[] x)	{		int [] ints = {1,2,3};		Integer [] integers = {1,2,3};		Base [] bases = {new Base(), new Base()};		Base [] mixed = {new Child(), new Base()};		test(new Integer[]{1,2,3});		test(integers);		// Invalid, autoboxing doesn't work:		//test(ints);		// Invalid syntatically:		//test({1,2,3});		List<String> a = ListFactory.create("Five", "Six", "Seven");		Integer[] b = ListFactory.createArray(new Integer[]{}, 1, 2, 3);		// Tests:		Object[][] objects = {a.toArray(new String[]{}),b};		for (Object[] ob : objects)		{			System.out.println(ob);			for (Object o : ob)				System.out.println(o);		}	}}