test/tools/javac/generics/6531090/T6531090b.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/generics/6531090/T6531090b.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6531090 6711619
    1.30 + *
    1.31 + * @summary Cannot access methods/fields of a captured type belonging to an intersection type
    1.32 + * @author Maurizio Cimadamore
    1.33 + *
    1.34 + */
    1.35 +public class T6531090b {
    1.36 +
    1.37 +    static class A {
    1.38 +        public void a1() {}
    1.39 +        protected void a2() {}
    1.40 +        void a3() {}
    1.41 +        public A a1;
    1.42 +        protected A a2;
    1.43 +        A a3;
    1.44 +    }
    1.45 +    static class B extends A {
    1.46 +        public void b1() {}
    1.47 +        protected void b2() {}
    1.48 +        void b3() {}
    1.49 +        public B b1;
    1.50 +        protected B b2;
    1.51 +        B b3;
    1.52 +    }
    1.53 +    static interface I{
    1.54 +        void i();
    1.55 +    }
    1.56 +    static interface I1{
    1.57 +        void i1();
    1.58 +    }
    1.59 +    static class E extends B implements I, I1{
    1.60 +        public void i() {}
    1.61 +        public void i1() {}
    1.62 +    }
    1.63 +    static class C<W extends B & I1, T extends W>{
    1.64 +        T t;
    1.65 +        W w;
    1.66 +        C(W w, T t) {
    1.67 +            this.w = w;
    1.68 +            this.t = t;
    1.69 +        }
    1.70 +    }
    1.71 +
    1.72 +    public static void main(String... args) {
    1.73 +        C<E,E> c = new C<E,E>(new E(), new E());
    1.74 +        testMemberMethods(c);
    1.75 +        testMemberFields(c);
    1.76 +    }
    1.77 +
    1.78 +    static void testMemberMethods(C<? extends A, ? extends I> arg) {
    1.79 +        arg.t.a1();
    1.80 +        arg.t.a2();
    1.81 +        arg.t.a3();
    1.82 +        arg.t.b1();
    1.83 +        arg.t.b2();
    1.84 +        arg.t.b3();
    1.85 +        arg.t.i1();
    1.86 +        arg.w.a1();
    1.87 +        arg.w.a2();
    1.88 +        arg.w.a3();
    1.89 +        arg.w.b1();
    1.90 +        arg.w.b2();
    1.91 +        arg.w.b3();
    1.92 +        arg.w.i1();
    1.93 +    }
    1.94 +
    1.95 +    static void testMemberFields(C<? extends A, ? extends I> arg) {
    1.96 +        A ta; B tb;
    1.97 +        ta = arg.t.a1;
    1.98 +        ta = arg.t.a2;
    1.99 +        ta = arg.t.a3;
   1.100 +        tb = arg.t.b1;
   1.101 +        tb = arg.t.b2;
   1.102 +        tb = arg.t.b3;
   1.103 +        ta = arg.w.a1;
   1.104 +        ta = arg.w.a2;
   1.105 +        ta = arg.w.a3;
   1.106 +        tb = arg.w.b1;
   1.107 +        tb = arg.w.b2;
   1.108 +        tb = arg.w.b3;
   1.109 +    }
   1.110 +}

mercurial