Java:在最终类中实现接口的类

jac*_*ast 2 java interface class

这可能是一个愚蠢的问题,但我在这里感到困惑.我有以下情况:

Main.java

public class Main {

    public static void main (String args[]){
        GenericTag[] arr = new GenericTag[2];
        arr[0] = new Authentication("", "", "", "");
        arr[1] = new Document("", "", "", "");
        byte[] foo= Base64.decodeBase64(XmlBuilder.generate(arr));
        System.out.println(new String(foo));
    }
Run Code Online (Sandbox Code Playgroud)

XmlBuilder.java

public final class XmlBuilder {
    private static final String OPEN_TAG = "";
    private static final String CLOSE_TAG = "";

    public static byte[] generate(GenericTag[] tags){

        String xml = OPEN_TAG;
        for(int i=0; i<tags.length; i++){
            xml += tags[i].xml;
        }
        xml += CLOSE_TAG;

        return Base64.encodeBase64(xml.getBytes());
    }

    public interface GenericTag{
         public String getXml();
    }

    public class Authentication implements GenericTag{
        private static final String OPEN_TAG = "<authentication>";
        private static final String CLOSE_TAG = "</autentication>";
        //some tags

        public Authentication (/*some parameters*/){
            xml = OPEN_TAG;
            //xml building
            xml += CLOSE_TAG;
        }

        @Override
        public String getXml() {
            return xml;
        }
    }

    public class Document implements GenericTag{
        private static final String OPEN_TAG = "<document>";
        private static final String CLOSE_TAG = "</document>";
        //some tags

        public String xml;

        public Documento (/*some params*/){
            xml = OPEN_TAG;
            //xml building
            xml += CLOSE_TAG;
        }
    @Override
    public String getXml() {
        return xml;
    }
    }
}
Run Code Online (Sandbox Code Playgroud)

我无法让它发挥作用.编译器说无法将Authentication和Document都解析为类型.如果我明确说明 new XmlBuilder.Authentication它说

No enclosing instance of type XmlBuilder is accessible. Must qualify the allocation with an enclosing instance of type XmlBuilder (e.g. x.new A() where x is an instance of XmlBuilder).
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

esi*_*n88 5

上课AuthenticationDocument public static.由于那些不是static,您只能从XmlBuilder实例中实例化它们.

Java内部类和静态嵌套类 - 您可以在此处找到更多信息