-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”列表中。然后你只需要使用“包含”方法。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 回答