是否可以在界面中创建内部类?如果有可能我们为什么要创建这样的内部类,因为我们不打算创建任何接口对象?
这些内部类有助于任何开发过程吗?
在Java中用接口定义类的能力的实际方面是什么:
interface IFoo
{
class Bar
{
void foobar ()
{
System.out.println("foobaring...");
}
}
}
Run Code Online (Sandbox Code Playgroud) 这让我在C#中遇到过一两次.我可以写这样的代码
class Node
{
class Connection
{
public Connection(Node node, string label)
{
this.Node = node;
this.Label = label;
}
public Node Node { get; private set; }
public string Label { get; private set; }
};
IEnumerable<Connection> IncomingConnections() // ...
IEnumerable<Connection> OutgoingConnections() // ...
}
Run Code Online (Sandbox Code Playgroud)
但如果我写
interface INode
{
class Connection
{
public Connection(INode node, string label)
{
this.Node = node;
this.Label = label;
}
public INode Node { get; private set; }
public string Label { get; private …Run Code Online (Sandbox Code Playgroud)