我如何理解public static Objective[]?

huangapple go评论75阅读模式
英文:

How do I understand the public static Objective[]?

问题

public class Objective {
    private int problemNumber;          // 原始棋盘游戏中的问题编号
    private String initialState;        // 初始图块摆放列表
    public static Objective[] OBJECTIVES = {
            // 初始任务
            new Objective("S0S6W3N8N2E5S7S18", 1),
            new Objective("N7N0S3N8S2S6E1S51", 2),
            new Objective("W8S6E2S5N0E4W1S31", 3),
            new Objective("S8S7W0E5S4N2W3S13", 4),
            new Objective("S1N2W0E7S6S8W3W58", 5),
            new Objective("W8N6E7S4N0W1N2S32", 6),
            new Objective("S2N0W1E8S7W4W6W38", 7),
            new Objective("S6N8W5E4W7W1S3N23", 8),
            new Objective("S3S7W6S4W1E5N2S05", 9),
            new Objective("S0S1N2N7S6W3N4S57", 10),
            new Objective("E2N8W7N1S6E4S3S06", 11),
            new Objective("N1S3W0W7N5E8E6S28", 12),
            // 更多任务...
    };

    public static Objective newObjective(int difficulty) {
        assert difficulty >= 0 && difficulty <= 4;
        return OBJECTIVES[0]; // 待修正 第5任务 (P)
    }

    public String getInitialState() {
        return initialState;
    }
    public int getProblemNumber() {
        return problemNumber;
    }

    public static Objective getObjective(int index) {
        return OBJECTIVES[index];
    }
    public static Objective[] getOBJECTIVES() {
        return OBJECTIVES;
    }
}

Please let me know if you need any further assistance or explanation about the code.

英文:
  public class Objective {
private int problemNumber;          // The problem number from the original board game
private String initialState;        // The list of initial tile placements
public static Objective[] OBJECTIVES = {
        // STARTER
        new Objective(&quot;S0S6W3N8N2E5S7S18&quot;, 1),
        new Objective(&quot;N7N0S3N8S2S6E1S51&quot;, 2),
        new Objective(&quot;W8S6E2S5N0E4W1S31&quot;, 3),
        new Objective(&quot;S8S7W0E5S4N2W3S13&quot;, 4),
        new Objective(&quot;S1N2W0E7S6S8W3W58&quot;, 5),
        new Objective(&quot;W8N6E7S4N0W1N2S32&quot;, 6),
        new Objective(&quot;S2N0W1E8S7W4W6W38&quot;, 7),
        new Objective(&quot;S6N8W5E4W7W1S3N23&quot;, 8),
        new Objective(&quot;S3S7W6S4W1E5N2S05&quot;, 9),
        new Objective(&quot;S0S1N2N7S6W3N4S57&quot;, 10),
        new Objective(&quot;E2N8W7N1S6E4S3S06&quot;, 11),
        new Objective(&quot;N1S3W0W7N5E8E6S28&quot;, 12),
        &quot;, 53),
       


public static Objective newObjective(int difficulty) {
    assert difficulty &gt;= 0 &amp;&amp; difficulty &lt;= 4;
    return OBJECTIVES[0]; // FIXME Task 5 (P)
}

public String getInitialState() {
    return initialState;
}
public int getProblemNumber() {
    return problemNumber;
}

public static Objective getObjective(int index) {
    return OBJECTIVES[index];
}
public static Objective[] getOBJECTIVES() {
    return OBJECTIVES;
}

I just learn Java for two weeks, I still have some questions about this code.

public static Objective[] OBJECTIVES = 

I don't understand this code. Is a method of the class?
public static Objective newObjective(int difficulty)
I also have no idea about this code.

答案1

得分: 1

public static Objective[] OBJECTIVES = { ...

这是一个已实例化的Objective对象数组该数组的可见性为public且是静态的因此它只会在该类中被创建一次需要注意的一点是Objective对象不是不可变的因此不应全部使用大写字母来定义因为它本质上是可变的

public static Objective newObjective(int difficulty)

代码表明应基于提供的难度级别返回一个新的Objective对象我推测这指的是底层数组中的索引

不过这个问题明显需要更多的焦点在将来请提一个只有一个焦点的问题并在可能的情况下提问时清晰明了
英文:

> public static Objective[] OBJECTIVES = { ...

This is an array of Objective objects that has been instantiated. The visibility of this array is public and the array is static so it is only created once for the Class. One thing to note is that Objective is not immutable and so this shouldn&#39;t be defined with all uppercase letters because it is inherently mutable.

> public static Objective newObjective(int difficulty)

The code suggests that a new Objective object should be returned based on the difficulty provided. I presume that refers to an index in the underlying array.

This question definitely needs more focus though. In the future ask a single question with a single point of focus and be clear when asking if possible.

huangapple
  • 本文由 发表于 2020年8月20日 20:25:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63505070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定