30.08.2017

Anonymous Inner class example

package ru.home;

interface Contents {
    int value();
}

public class Main {
    public static void main(String[] args) {
        Main p = new Main();
        Contents c = p.contents();
        System.out.println(c.value()); //Is 11
    }

    private Contents contents() {
        return new Contents() {
            private int i = 11;
            public int value() {
                return i;
            }
        };
    }
}

Комментариев нет:

Отправить комментарий