I am reading about what an interface contains and I understand in addition to the usual they can also contain inner classes or other interface.
Can anyone explain why or for what purpose anyone would want to put an interface inside an interface. Also why would anyone put an inner class inside. I have looked on the net but not found any good explanations other than a link that points to one of the standard java classes. What I really need to help me understand is a simple example.
Here's an excerpt from an interface of mine that uses an inner class:
public interface EmailService {
void send(EmailDetails details);
class EmailDetails {
private String from;
private List<String> to = Lists.newArrayList();
private String messageTemplate;
//...
}
}
You see - the point is that the interface needs some additional definition (in this case - the parameter its method accepts). It would be the same thing with an inner interface.
It could've been a separate class/interface, but as it is only relevant to this interface, I put it there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With