How to import a package from Eclipse?

前端 未结 3 747
攒了一身酷
攒了一身酷 2021-01-12 02:39

In one of my directories I have all .java files which belong to one package (\"game\"). Now I want to create one .java file which does not belong to this package and which i

3条回答
  •  日久生厌
    2021-01-12 03:26

    You cannot import a package, you need to import classes from that package:

    import game.SomeClass;
    import game.SomeOtherClass;
    

    or

    import game.*;
    

    to import all classes from that package.

    Eclipse can generate these imports for you if you type the class-names in your code and press Ctrl+Space for Code-Completion. Select the correct class there (if more classes with the same name exist in different packages), and the import will be generated.

提交回复
热议问题