简体   繁体   English

如何在eclipse项目中有2个同名文件但在2个不同的子文件夹中?

[英]How can I have 2 files of the same name in an eclipse project but in 2 different sub-folders?

Right now I have a set up like this: 现在我有这样的设置:

...\\lab18\\18a\\18a.java ... \\ lab18 \\ 18A \\ 18a.java

...\\lab18\\18a\\monster.java ... \\ lab18 \\ 18A \\ monster.java

and

...\\lab18\\18b\\18b.java ... \\ lab18 \\ 18B \\ 18b.java

...\\lab18\\18b\\monster.java ... \\ lab18 \\ 18B \\ monster.java

the issue is the 2 'monster.java' files in the 18a and 18b sub-folders, is there a way to keep these names the same but not cause errors on the 'monster.java' in the 18b, 18c, etc sub-folders? 问题是18a和18b子文件夹中的2'yarge.java'文件,有没有办法保持这些名称相同但不会导致18b,18c等子中'monster.java'的错误文件夹? The error eclipse is stating is that Monster is already defined referencing to the .java file in the 18a folder. 错误eclipse说明Monster已经定义为引用18a文件夹中的.java文件。

here is a screenshot of what I'm referring to: 这是我所指的截图: 问题的截图

Here is a screenshot of how the files and folders are organized in Windows explorer: 以下是Windows资源管理器中文件和文件夹的组织截图: Windows Explorer截图

Same source folder, two packages: 相同的源文件夹,两个包:

在此输入图像描述


Package declaration in the Java classes Java类中的包声明 在此输入图像描述

-> Same project, same source folder, different packages, same class name. - >相同的项目,相同的源文件夹,不同的包,相同的类名。

You have put them into the same package (default package) within two different source folders. 您已将它们放在两个不同源文件夹中的同一个包(默认包)中。 The only way you will be able to have two classes with the same name is if they are in different packages. 只有两个类具有相同名称的唯一方法是它们位于不同的包中。

For example, for lab18 one, put it into a subfolder called lab 18a and put lab18b into a subfolder called lab18b 例如,对于lab18 one,将其放入名为lab 18a的子文件夹中,并将lab18b放入名为lab18b的子文件夹中

lab18_oop_interfaces
  lab18a
    lab18a
      Lab18a.java
      Monster.java
  lab18b
    lab18b
      Lab18b.java
      Monster.java

Alternatively, put both the subfolders into one src folder and mark that as the source folder: 或者,将两个子文件夹放在一个src文件夹中,并将其标记为源文件夹:

lab18_oop_interfaces
  src
    lab18a
      Lab18a.java
      Monster.java
    lab18b
      Lab18b.java
      Monster.java

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Jars的eclipse中设置类路径(在多个子文件夹中) - How to set classpath in eclipse for Jars (in multiple sub-folders) 我们如何在容器下创建子文件夹我的问题有些不同 - How can we create sub-folders under a container my problem is some this different 如何仅从子文件夹的构建路径中删除项目 - How to remove project from build path for sub-folders only 如何在同一个Eclipse项目中使用不同类型的构建器/源文件夹 - How to have builders/source-folders of different types in same eclipse project 如何在 Eclipse/Gradle/Java 项目中,项目名称和根项目目录可以有不同的名称? - How in Eclipse/Gradle/Java project one can have different names for a project name and a root project directory? 如何将Jar中的资源目录以及所有包含的文件和子文件夹复制到另一个目录中 - How to copy a resource directory and all included files and sub-folders in a Jar onto another directory 我可以在Eclipse IDE的一个Java项目中使用同名的类吗? - Can I have classes with same name in one Java project in Eclipse IDE? 在同一项目中为Eclipse中的不同源文件夹设置不同的编译器级别 - Setting different compiler levels for different source folders in eclipse in same project 如何使用POP3检索gmail子文件夹/标签? - How to retrieve gmail sub-folders/labels using POP3? 有没有办法我可以列出特定文件夹中的所有文件,包括在java的帮助下来自所有子文件夹的文件? - is there way I could list all the documents from a particular folder including files from all it's sub-folders with the help of java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM