UnsoundInference.java revision 0:9a66ca7c79fa
1169689Skan/* 2169689Skan * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4169689Skan * 5169689Skan * This code is free software; you can redistribute it and/or modify it 6169689Skan * under the terms of the GNU General Public License version 2 only, as 7169689Skan * published by the Free Software Foundation. 8169689Skan * 9169689Skan * This code is distributed in the hope that it will be useful, but WITHOUT 10169689Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11169689Skan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12169689Skan * version 2 for more details (a copy is included in the LICENSE file that 13169689Skan * accompanied this code). 14169689Skan * 15169689Skan * You should have received a copy of the GNU General Public License version 16169689Skan * 2 along with this work; if not, write to the Free Software Foundation, 17169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18169689Skan * 19169689Skan * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20169689Skan * CA 95054 USA or visit www.sun.com if you need additional information or 21169689Skan * have any questions. 22169689Skan */ 23169689Skan 24169689Skan/* 25169689Skan * @test 26169689Skan * @bug 5020448 27169689Skan * @summary Generic method allowing passing of types that don't match collection types 28169689Skan * @author gafter 29169689Skan * 30169689Skan * @compile/fail -source 1.5 UnsoundInference.java 31169689Skan */ 32169689Skan 33169689Skanimport java.util.ArrayList; 34169689Skanimport java.util.Collection; 35169689Skan 36169689Skanpublic class UnsoundInference { 37169689Skan 38169689Skan public static void main(String[] args) { 39169689Skan Object[] objArray = {new Object()}; 40169689Skan ArrayList<String> strList = new ArrayList<String>(); 41169689Skan transferBug(objArray, strList); 42169689Skan String str = strList.get(0); 43169689Skan } 44169689Skan 45169689Skan public static <Var> void transferBug(Var[] from, Collection<Var> to) { 46169689Skan to.add(from[0]); 47169689Skan } 48169689Skan} 49169689Skan