关于Algs4书中导入Stdlib.jar 和 algs4.jar包的问题

来源:互联网 发布:服装批发记账软件 编辑:程序博客网 时间:2024/06/05 04:45

在Algs4中导入Stdlib.jar 和 algs4.jar包后程序仍然无法使用包中已定义的函数,并且程序无法 import相应的类。试了很多方法不成功,后面看到官网下载这两个包网页的底部有答疑:

这里就不强调如何在eclipse导入第三方jar包了。

Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar or algs4.jar. Why not?

A. The libraries in stdlib.jar and algs4.jar are in the "default" package. In Java,you can't access classes in the default package from a named package. If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.


加粗部分说你无法从已命名(非default)的包中调用默认名称(default)包中的class文件,

这里stdlib.jar下面包的名字是default package


所以现在有两种解决方法:

1、不要新建包,直接用系统默认的包(名称是default)这样就可以正常使用了,如下:




2、或者 看

If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.

这句话我们可以下载上述两个包,用这两个包导入就可以任意指定包名了,如下:



祝好运~~~~

0 0
原创粉丝点击