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

Java example source code file (T7132880.java)

This example Java source code file (T7132880.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

inner1, inner2, inner3, inner4, inner5, object, outer

The T7132880.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 7132880
 * @summary Resolve should support nested resolution contexts
 * @compile/fail/ref=T7132880.out -XDrawDiagnostics T7132880.java
 */
class Outer {
    void m1(String s) { }
    void m2(int i1, int i2) { }

    class Inner {
        void test() {
           //ok - no method named 'm' in Inner - hence, class to search is Outer
           m1("");
        }
    }

    class Inner1 {
        void m1(Integer i) { }

        void test() {
           //error - Inner1 defines an incompatible method - hence, class to search is Inner1
           m1("");
        }
    }

    class Inner2 {
        private void m1(Integer i) { }
        private void m1(Double d) { }

        void test() {
           //error - Inner2 defines multiple incompatible methods - hence, class to search is Inner2
           m1("");
        }
    }

    class Inner3 {
        private void m2(Object o, int i) { }
        private void m2(int i, Object o) { }

        void test() {
           //error - Inner3 defines multiple ambiguous methods - hence, class to search is Inner3
           m2(1, 1);
        }
    }

    class Inner4 extends Inner2 {
        void test() {
           //ok - Inner2 defines multiple incompatible inaccessible methods - hence, class to search is Outer
           m1("");
        }
    }

    class Inner5 extends Inner3 {
        void test() {
           //ok - Inner3 defines multiple inaccessible ambiguous methods - hence, class to search is Outer
           m2(1, 1);
        }
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java T7132880.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.