java - 围绕 superfirst 工作

标签 java constructor restrictions jls defensive-programming

这里,AsciiChecker启用文本形式的矩阵规范。

abstract class AsciiChecker extends AlgoritmicChecker {

    String[] ascii;

    AsciiChecker(String title, final String ... ascii) {
        super(title, ascii[0].length(), ascii.length); // calls isCovered
    };

    boolean isCovered(int test, int statement) {
        return ascii[statement].charAt(test) == '1';
    }           
}

它需要矩阵参数在 isCovered 调用中可用。告诉我如果我在使用前初始化 field ,我该如何射击我的腿,

    AsciiChecker(String title, final String ... ascii) {
        this.ascii = ascii;
        super(title, ascii[0].length(), ascii.length); // calls isCovered
    };

最佳答案

如果您的父类(super class)正在使用数组中的数据,请将 String[] ascii; 拉到父类(super class),在那里初始化此字段,并在 isCovered 中通过 getter 访问它或修改isCovered 的签名并传递适当的数组作为参数。

关于java - 围绕 superfirst 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19566631/

相关文章:

c++ - 限制整数模板参数

java - 如何自定义 ModelMapper

JavaScript继承: subtype prototype cannot visit super type's property/function

C++ 为什么这个可以抛出?

c++ - 使用其他对象的类构造函数

c++ - 一个 'friend of a Class' 的函数允许 'read access' 到它的 'private members' 但不是 'write access' ?

java - 为什么我的网格没有从 'O' 更新到 'S'(数组)

java - 具有合成时间戳的 Spark 窗口函数?

java - 如何在android studio中添加图像文件并获取其uri?

java - hibernate 条件 : search by content on a property list in an entity