内部接口? [英] Inner Interfaces?

查看:142
本文介绍了内部接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java很陌生,我不明白这个结构是什么。我知道什么是接口以及如何定义,但在这种情况下,我真的不知道。你能告诉我们是什么吗?

I'm pretty new to Java and I don't understand what is this structure. I know what is an interface and how is defined, but in this case, I really don't know. Could you tell what is about?

public interface WebConstants {
    public interface Framework {
        String ACTION = "action";
    }

    public interface Look {
        String LIST_CONT = "list.cont";
    }
}


推荐答案

你如果您正在考虑使用类似的解决方案,可能需要查看枚举:

You might want to look into enums if you're looking at using a similar solution:

public enum WebConstants
{
    ACTION("action"), LIST_COUNT("list.count");

    private String display;

    private WebConstants(String display)
    {
        this.display = display;
    }

    public String getDisplay()
    {
        return display;
    }
}

所以你可以用它来调用WebConstants.ACTION.getDisplay ()。

So you could use it calling WebConstants.ACTION.getDisplay().

拥有一个常量接口对我来说没有任何意义。更好的处理方法可能是使用抽象访问器方法。

Having an interface of constants doesn't really make any sense to me. A better way of doing things might be to have abstract accessor methods.

public interface ActionAware
{
    public String getAction();
}

public interface ListCountAware
{
    public String getListCount();
}

public abstract class AbstractUseCase implements ActionAware, ListCountAware
{

    public void doSomething()
    {
        String action = getAction();
        String listCount = getListCount();
    }

}

public final class SpecificUseCase extends AbstractUseCase
{
     public final static String ACTION = "specific.action";
     public final static String LIST_COUNT = "specific.list.count";

     public String getListCount()
     {
         return LIST_COUNT;
     }

     public String getAction()
     {
         return ACTION;
     }

     // other methods

}

这篇关于内部接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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