I am trying to understand the below behavior, all I am trying is to initialize the static variable of interface via enum method.
enum Hello {
ProfileResolver();
public Hello resolve() {
System.out.println("resolve method called!!!!");
return ProfileResolver;
}
}
public interface Resolver{
Hello hello = Hello.ProfileResolver.resolve(); // this should called when creating an instace of any implementation
}
Implentation class like below
public class Impl implements Resolver{
}
and now if
public static void main(String[] arg){
Resolver resolver = new Impl();
}
Now at this point I was expecting just before object initialization of Impl
object, hello variable of Interface must initialize and resolve method called, but it is not.
And when I declare Resolver as class instead of inteface, it is working as expected.
Can anyone help me try to understand ?