Java – is it a good idea to nest a class in an interface?

Is it possible to have an internal class inside the interface in Java???

Solution

You can But that's what O'Reilly said:

Nested classes in interfaces?

Java supports the concept of nested classes in interfaces Syntax and dynamics work like nested classes declared in a class However, declaring classes nested within interfaces would be very bad programming Interfaces are abstractions of concepts, not implementations Therefore, the implementation details should omit the interface Remember, just because you can cut off your hand with a saw doesn't mean it's a particularly good idea

That is, I can see the parameters of the static utility class nested in the interface Although why it needs to be nested into the interface rather than a separate class is completely subjective

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>