Where is it useful to have nested classes in an interface?
There is no such case that can only be done with an internal class of an interface. It is syntactically fair to have an inner class in the interface, and for a class that implements the interface, it can create an instance of the class, and in addition, Interface.Class can also make this class available, since it cannot be private at all.
I noticed that if Test did not implement Iface, then after import I needed import com.jls.Iface.ifaceClass;
Not necessarily, if your interface is available, your inner class will automatically become available. If you are trying to access the class directly without even importing an interface , in this case the following statement should be given above the import statement.
ifaceClass ifaceClassObj = new ifaceClass();
But it came down to the same problem, why not use it as a fair other class. What is the difference or value addition with this approach
Similarly, creating another class can also provide you with the same object, and I have never seen any use in my day-to-day programming that can only be accomplished using an internal interface class. It provides nothing but accessibility through an interface.
I used it once, which I think is pretty bad practice. Once we need to implement one common method in different classes that implement the interface, say X , and we wanted to add one additional method that all these classes will use to add one kind of check on Object , which checks only some parameters and return boolean . although this use case can be done in a different way, but for the specific one, that it is intended only for classes that implement this interface, we added a class to the interface so that we can provide this method for implementation classes. (NOTE: Currently, the default method can be used in this case instead of the inner class)
It is worth noting here that in huge projects for anyone (except the creator) it is completely impossible to notice that any interface has an internal class. So, until we implement this class or manually check the interface, we cannot understand that the interface has an internal class.