English 中文(简体)
Java
原标题:Load Inner Class Java

我在贾瓦(从JacoCo项目开始):

public class MemoryMultiReportOutput implements IMultiReportOutput {

    private final Map<String, ByteArrayOutputStream> files = new HashMap<String, ByteArrayOutputStream>();

    private final Set<String> open = new HashSet<String>();

    private boolean closed = false;

    public OutputStream createFile(final String path) throws IOException {
        assertFalse("Duplicate output " + path, files.containsKey(path));
        open.add(path);
        final ByteArrayOutputStream out = new ByteArrayOutputStream() {
            @Override
            public void close() throws IOException {
                open.remove(path);
                super.close();
            }
        };
        files.put(path, out);
        return out;
    }

    public void close() throws IOException {
        closed = true;
    }

    public void assertEmpty() {
        assertEquals(Collections.emptySet(), files.keySet());
    }

    public void assertFile(String path) {
        assertNotNull(String.format("Missing file %s. Actual files are %s.",
                path, files.keySet()), files.get(path));
    }

    public void assertSingleFile(String path) {
        assertEquals(Collections.singleton(path), files.keySet());
    }

    public byte[] getFile(String path) {
        assertFile(path);
        return files.get(path).toByteArray();
    }

    public InputStream getFileAsStream(String path) {
        return new ByteArrayInputStream(getFile(path));
    }

    public void assertAllClosed() {
        assertEquals(Collections.emptySet(), open);
        assertTrue(closed);
    }
}

当我汇编这一类别时,Eclipse 创建。 MemoryMultiReportOutput.nal and MemoryMultiReportOutput$1.qu

第一问题: 为什么Eclipse创建 记忆-结果报告 Eclipse consider the Byte ArrayOutputStream out a InnerClass?

但我的问题是,当我装上<代码>时。 MemoryMultiReportOutput.nal 我怎么能够装上括母阶级中的所有内层?

最佳回答

回答你的第一个问题:

final ByteArrayOutputStream out = new ByteArrayOutputStream() {
        @Override
        public void close() throws IOException {
            open.remove(path);
            super.close();
        }
    };

在这里,你正在制作一张由拜特阿雷拉OutputStream组成的子级,即匿名。 正因为如此,你还有另一档。

回答您的第二个问题:

仅能通过超级等级的试金字标装母体内班:

Superclass s = new Superclass();
Superclass.Subclass sub = s.new Subclass();

如果内产阶级是静态的,即:上下级 (因为没有静态等级,所以可以立即进行:

Superclass.Subclass s = new Superclass.Subclass();

不需要超级阶级的反对。

希望这一帮助!

问题回答

你与你一起创建匿名内科

new ByteArrayOutputStream()

因此,请见<代码>。 MemoryMultiReportOutput$1.nal file.

你不需要做任何事情来装上内部班。 这将自动发生。

如果您询问如何从另一类中选取比较少的那类人。 您需要打上<条码> 公开<>/条码>,或提供一种接驳机,以交回这门课程。 你们问什么?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签