相关疑难解决方法(0)

Interface中的内部类

是否可以在界面中创建内部类?如果有可能我们为什么要创建这样的内部类,因为我们不打算创建任何接口对象?

这些内部类有助于任何开发过程吗?

java oop interface inner-classes

89
推荐指数
7
解决办法
7万
查看次数

在Java中用接口定义类的能力的实用方面?

在Java中用接口定义类的能力的实际方面是什么:

interface IFoo
{
    class Bar
    {
        void foobar ()
        {
            System.out.println("foobaring...");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java interface inner-classes

12
推荐指数
4
解决办法
4276
查看次数

为什么接口不能包含类型?

这让我在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)

c#

9
推荐指数
1
解决办法
1728
查看次数

标签 统计

inner-classes ×2

interface ×2

java ×2

c# ×1

oop ×1