Java : Inner class of an interface (from google guice)

Posted by bsreekanth on Stack Overflow See other posts from Stack Overflow or by bsreekanth
Published on 2010-12-31T15:52:24Z Indexed on 2010/12/31 15:53 UTC
Read the original article Hit count: 203

Filed under:
|

Hello,
I was going through the source of google guice, and found an unfamiliar piece of code. It would be great learning if someone can clarify it.

I have very basic understanding of inner classes, as they keep the implementation details close to the public interface. Otherwise the inner class may pollute the namespace.

Now, I see the below lines at

public static final Scope SINGLETON = new Scope() {
    public <T> Provider<T> scope(final Key<T> key, final Provider<T> creator) {
      return new Provider<T>() {
.........
}

It assign an inner class instance to the static variable, but Scope is an interface defined as (at)

public interface Scope

Is it possible to instantiate the interface?? or is it a succinct syntax for an anonymous implementation of an interface??

If anyone can explain what the author is intended by multiple nested classes above (Scope and Provider), and why it make sense to implement this way, it would help me to understand. thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about guice