-1
// test for rock
        List rocks = getWorld().getObjectsAt(x , y, Rock.class);

        /* Look up the List class (java.util.List) in the Java API
         * and determine what method to use with the 'rocks' List
         * to determine if there was a rock. Put the correct test
         * in the 'if()' statement below.
         */

        if () {
            return true;
        }

        return false;

上記の「if()」ステートメントに記入する必要があります return true; lst を使用して if ステートメントを取得する方法を本当に混乱させました。助けてください!やり方の知識を発信!どうもありがとうございました!

4

2 に答える 2

0

私の理解が正しければ、あなたが望むのは、具体的なオブジェクト Rock がリスト「rocks」にあるかどうかを確認することです。次に、「contains」メソッドを使用するだけです。public boolean List.contains(Object o) は、オブジェクト「o」がリストに存在するかどうかを確認します。

Rock myRock = //whatever sentence you use to create the rock you're checking

if (rocks.contains(myRock) {
    return true;
}

return false;
于 2014-11-13T19:29:21.383 に答える
0

どうですか:

if (!rocks.isEmpty()) { //is true if your list with rocks is not empty
    return true;
}
于 2015-01-07T19:14:15.940 に答える