Java错误:找不到符号Rational()

用户名

我只根据教师的喜好使用acm软件包。
该程序应该分配10000个有理对象,以便它们成为垃圾,然后在使用垃圾收集器之前和之后计算可用内存。然后,应该打印出垃圾回收器清除的内存量。

import acm.program.*;

public class RuntimeGarbage extends ConsoleProgram {
    public void run() {
        println("Allocating 10000 Rational Objects");
        for(int i=1; i==10000; i++) {
            new Rational();
        }
        Runtime myRuntime = Runtime.getRuntime();
        long free_before = myRuntime.freeMemory();
    myRuntime.gc();
    long free_after = myRuntime.freeMemory();
    println("Garbage collection freed" + ((free_after)-(free_before)) + "bytes");
    }
}


问题是,当我尝试编译代码时,cmd显示以下内容:

:8: error: cannot find symbol 
new Rational(); 
with an arrow right below the R. 

可能是问题出在大括号内吗?

火柴人

编译器在说什么,它不知道在哪里定义Rational类型。是的,您可以在for循环的代码块中创建对象。

根据google的说法,acm包中未定义Rational类型

rational site:www-cs-faculty.stanford.edu/~eroberts/jtf/javadoc/student/acm/

因此它必须在其他地方定义。

它看起来并不属于内置Java类型,无论是http://docs.oracle.com/javase/7/docs/api/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章