Reputation: 1
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.
Upvotes: 0
Views: 573
Reputation: 1500065
EDIT: Okay, through comments I think we've actually got to the bottom of the problem. The situation is:
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.
Upvotes: 1
Reputation: 393781
If Eclipse would let you create a class with the same name in the same package, it would override the existing file containing the original class.
Eclipse assumes that such an attempt is an error on your part.
You have no reason to do that, since you can simply edit the existing class.
Upvotes: 0