2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-05-15 17:12:58 -07:00
|
|
|
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:54:51 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 4916607
|
2015-05-15 17:12:58 -07:00
|
|
|
* @summary Test casts (warning)
|
2007-12-01 00:00:00 +00:00
|
|
|
* @author gafter
|
|
|
|
*
|
2015-05-15 17:12:58 -07:00
|
|
|
* @compile/ref=CastWarn.out -XDrawDiagnostics -Xlint:unchecked CastWarn.java
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
2015-05-15 17:12:58 -07:00
|
|
|
class CastWarn {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// --- Disjoint ---
|
|
|
|
|
|
|
|
private interface DA<T> { }
|
|
|
|
private interface DB<T> extends DA<T> { }
|
|
|
|
private interface DC<T> extends DA<Integer> { }
|
|
|
|
|
|
|
|
private <N extends Number, I extends Integer, R extends Runnable, S extends String> void disjointness() {
|
|
|
|
Object o;
|
|
|
|
|
2015-05-15 17:12:58 -07:00
|
|
|
// Classes
|
2007-12-01 00:00:00 +00:00
|
|
|
o = (DA<? extends Runnable>) (DA<? extends Number>) null; // <<warn 2>>
|
2015-05-15 17:12:58 -07:00
|
|
|
o = (DA<? super Integer>) (DA<? extends Number>) null; // <<warn 3>>
|
|
|
|
o = (DA<? super String>) (DA<? super Number>) null; // <<warn 4>>
|
|
|
|
|
|
|
|
// Typevars
|
|
|
|
o = (DA<? extends Integer>) (DA<N>) null; // <<warn 5>>
|
|
|
|
o = (DA<I>) (DA<? extends Number>) null; // <<warn 6>>
|
|
|
|
o = (DA<N>) (DA<? extends Integer>) null; // <<warn 7>>
|
|
|
|
o = (DA<N>) (DA<? extends Runnable>) null; // <<warn 8>>
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-05-15 17:12:58 -07:00
|
|
|
o = (DA<N>) (DA<I>) null; // <<warn 9>>
|
|
|
|
o = (DA<N>) (DA<R>) null; // <<warn 10>>
|
|
|
|
|
|
|
|
// Raw (asymmetrical!)
|
|
|
|
o = (DA<Number>) (DB) null; // <<warn 11>>
|
|
|
|
o = (DA<? extends Number>) (DB) null; // <<warn 12>>
|
|
|
|
o = (DB<Number>) (DA) null; // <<warn 13>>
|
|
|
|
o = (DB<? extends Number>) (DA) null; // <<warn 14>>
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|