alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (QualifiedAccess_2.java)

This example Java source code file (QualifiedAccess_2.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

error, foo, inner, myerror, object, quem, quux

The QualifiedAccess_2.java Java example source code

/**
 * @test  /nodynamiccopyright/
 * @bug 4094658 4277300 4785453
 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
 * the type to which a component member belongs be accessible in qualified
 * names.
 *
 * @compile pack1/P1.java
 * @compile pack1/P2.java
 * @compile/fail/ref=QualifiedAccess_2.out -XDrawDiagnostics QualifiedAccess_2.java
 */

import pack1.P1;

class A {
    private static class B {
        static class Inner {}
    }
}

class X extends pack1.P1 {
    X() { super("bar"); }
    void foo() {
        /*-----------------*
        // BOGUS: Reports matching constructor not found.
        // OK if 'Q' is made a public constructor.
        Object y = new Q("foo");// ERROR - protected constructor Q inaccessible
        *------------------*/
        // Reports 'P1.R.S' not found at all. (private)
        Object z = new R.S.T();         // ERROR - S is inaccessible
    }
}

class Y {

    class Foo {
        class Bar {}
    }

    class C extends A.B {}              // ERROR - B is inaccessible
    class D extends A.B.Inner {}        // ERROR - B is inaccessible

    static class Quux {
        private static class Quem {
            P1.Foo.Bar x;               // ERROR - Foo is inaccessible
            static class MyError extends Error {}
        }
    }
}

class Z {
    void foo() throws Y.Quux.Quem.MyError {
                                // ERROR - type of Quux not accesible (private)
        throw new Y.Quux.Quem.MyError();
                                // ERROR - type of Quux not accesible (private)
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java QualifiedAccess_2.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.