I came across a piece of code that I don't entirely understand.
There is an interface that is created within a class like this:
public class SomeClass {
public interface SomeInterface{
public String getInfo(String str1, String str2);
}
public static final SomeInterface SomeOtherName = new SomeInterface() {
@Override
public String getInfo(String str1, String str2){
//return something;
}
}
}
and then in another class they call the method getInfo
using SomeOtherName
. I don't understand what is going on here. To be honest I have not created an interface while in a class and then create an object of that interface type and then override methods in it. Can someone please explain me what is going on in this piece of code as I need to test it.