-1

I have two top-level classes; each has an inner class with the same name:

    **A.java**
    public class A
    {
    }
    class TestCase
    {
    }

    **B.java**
    public class B
    {
    }
    class TestCase
    {
    }

My expectation is that I will wind up with four class files, including A$TestCase.class and B$TestCase.class, which is what I get when I compile from the command line. Eclipse, however, just creates TestCase.class, and declares that "The type TestCase is already defined" when I try to compile B.java.

Is there an Eclipse option that I can set to produce (what I believe is the standard) A$TestCase.class and B$TestCase.class?

Thanks.

By the way, I am using Luna: Version: Luna Release (4.4.0) Build id: 20140612-0600

Jack Straub
  • 452
  • 3
  • 13

3 Answers3

2

Both versions of TestCase are top level classses. You need to create inner classes

public class A {
    class TestCase {
    }
}
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • OK, it's not an inner class (which is another question I've had for a while: what is it called?). Nevertheless, the Java compiler, invoked from the command line, produces A$TestCase.class and B$TestCase.class. How can I persuade Eclipse to do the same thing? – Jack Straub Oct 01 '14 at 21:28
  • Eclipse will produce the same "dollar files" as the command-line compiler – Reimeus Oct 01 '14 at 21:38
0

It doesn't do this for me. It creates an A$TestCase.class and a B$TestCase.class, as it should.

But this is only when they're actually inner classes... in your case, they're not really inner classes at all.

chiastic-security
  • 20,430
  • 4
  • 39
  • 67
0

TestCase is not an inner class as you might think, and this is why formatting code is essential when coding. check this

Community
  • 1
  • 1
Curcuma_
  • 851
  • 2
  • 12
  • 37