Java : Inner class of an interface (from google guice)
- by bsreekanth
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.