使用在Java中扩展另一个的空接口的目的是什么? [英] What is the purpose for using an empty interface that extends another in Java?

查看:115
本文介绍了使用在Java中扩展另一个的空接口的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始维护一个使用Java Guice Framework的Java MVC项目。

I just begin to maintain a Java MVC project which use Java Guice Framework.

在几乎整个代码中,第一个开发人员作为参数传递一个空模型接口扩展另一个界面。

In almost the entire code, first developers passed as parameter an empty model interface extending another interface.

这是第一个界面:

public interface FooModel extends ModelInterface {

}

另一个interface:

And the other interface:

 public interface ModelInterface {
        public void addListener(FooListener fooListener);
        void setFoo(boolean blop);
        boolean isFoo();
    }

这对我没有任何意义。

在Java中是否有一个很好的理由/模式使用空接口?也许对于Guice来说?

Is there a good reason/pattern use empty interface, in Java? Maybe for Guice?

推荐答案

这里是标记界面的一个很好的动机。它们在面向方面的编程中特别有用,它们给你一个附加点(我猜Guice就是这样一个框架)。

Here is a good motivation for "marker interfaces". They are especially useful in aspect-oriented programming where they give you a point to attach to (and I guess Guice is just such a framework).

这篇关于使用在Java中扩展另一个的空接口的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆