why same class file in eclipse not overwriting and showing error type already defined

created a "java" class in eclipse, when try to use same class name in same package again it showing error "type already defined". when write program in notepad and running in command prompt it overwriting class and not showing error, why not overwriting when using eclipse, to overwrite what need to do.

Jon Skeet
people
quotationmark

EDIT: Okay, through comments I think we've actually got to the bottom of the problem. The situation is:

  • Compiling under Windows
  • There are two classes in the same file, with the same name except for case
  • The command-line compiler doesn't noticed that the two class files will become one due to Windows file system case-insensitivity, but Eclipse does

So as an example:

class Foo {}
class foo {}

The Eclipse error message also makes this pretty clear, by mentioning case:

Class file collision: A resource exists with a different case: '/Sandbox/bin/Foo.class'.

As with my earlier answer, my advice is still the same don't do this.


Earlier answer...

I suspect that when you used the same name in a different file and compiled from the command line, you only specified one of them to compile - whereas Eclipse will try to compile all the classes present. If you specified both of the files, you would have got an error:

For example:

X.java
class Foo {}

Y.java
class Foo {}

> javac X.java Y.java
Y.java:1: error: duplicate class: Foo
class Foo {}
^
1 error

Basically, don't do this. Either rename one of the classes, or delete one of the files.

people

See more on this question at Stackoverflow