Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 545827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:48:11+00:00 2026-05-13T10:48:11+00:00

I’m getting an anonymous class at compile-time that I’m not expecting. Relevant code follows,

  • 0

I’m getting an anonymous class at compile-time that I’m not expecting. Relevant code follows, then a more detailed explanation:

Entirety of CircuitType.java:

public enum CircuitType { V110A20, V110A30, V208A20, V208A30 }

From Auditor.java, lines 3-9:

public class Auditor {
    private String[] fileNames;
    private int numV110A20;
    private int numV110A30;
    private int numV208A20;
    private int numV208A30;

From Auditor.java, lines 104-121:

[...]
switch (newCircuit.getType()) {
    case V110A20:
        this.numV110A20++;
        break;
    case V110A30:
        this.numV110A30++;
        break;
    case V208A20:
        this.numV208A20++;
        break;
    case V208A30:
        this.numV208A30++;
        break;
    default:
        System.err.println("An Error Has Occured.");
        System.exit(-1);
        break;
}
[...]

From Circuit.java, lines 1-5:

public class Circuit {
    private CircuitType myType;
    public CircuitType getType() {
        return this.myType;
    }
[...]

When the command

javac *.java

is executed, an anonymous class Auditor$1.java is generated. The files, obviously, all sit next to each other in a file system directory that contains nothing else.

When lines 104-121 are commented out, no anonymous class is generated.

I at first thought it was a package issue, so put the three classes in a package, but I didn’t know enough about packages to get it working. If it’s truely a package issue, can someone step me through exactly how to label them? I’d rather not have to package them if I don’t have to, though.

The reason the anonymous class is a problem, besides the fact that such classes usually signify a namespace issue, is that it breaks my Makefile I use for automatic compilation.

Update


Attached is a console session which I hope may shed light on this mystery:

% javap 'Auditor$1'
Compiled from "Auditor.java"
class Auditor$1 extends java.lang.Object{
    static final int[] $SwitchMap$CircuitType;
    static {};
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:48:11+00:00Added an answer on May 13, 2026 at 10:48 am

    I’ve gone ahead and built a little project containing the source you posted and just enough framework around it to make it compile. I got 3 class files: Circuit.class, CircuitType.class and Auditor.class – as expected.

    All this under Java 1.6. But as others have indicated, I think your diagnosis of the problem is off.

    Anonymous classes are easy to generate accidentally: Typically a construct like

    Circuit myCircuit = new Circuit() {
       public CircuitType getCircuitType() {
          return XXX;
       }
    }
    

    will create one, for example. Given more of your code, the good SO folks might be able to pinpoint your error.

    It might be interesting and instructive to disassemble your class files with javap or better yet a “real” Java disassembler like JD.


    Update

    Added your new Auditor code to mine… no change. No anonymous classes.

    Your code is of course correct (to the extent we can see it) but the design is not very OO. Some people would point out that you’ll have to extend your counter declarations and your switch statement every time a new circuit type appears.

    You’re also not making much use of the “special features” of enums. I have a much simplified version of your Auditor method:

       private int[] counters = new int[CircuitType.values().length];
    
       public void tallySomething() {
          Circuit newCircuit = new Circuit();
          counters[newCircuit.getType().ordinal()]++;
      }
    

    Update 2

    I found your javap output quite illuminating. See my comment below.

    My conclusions:

    1. Yes, apparently your Java impl is using an anon class for the switch. Lame, but legitimate.
    2. You have the following options:
      • eliminate the switch
      • use a different Java implementation
      • live with the anonymous class; ditch make and use ant to embrace the anon classes and other strangenesses of Java.

    Since you’re only having problems because of your non-standard compilation setup, I’d go with the last solution and attack the problem there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 305k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer However suppose you have one hundred objects used in an… May 13, 2026 at 8:57 pm
  • Editorial Team
    Editorial Team added an answer Using properties has a couple of distinct advantages: It allows… May 13, 2026 at 8:57 pm
  • Editorial Team
    Editorial Team added an answer you get this error because of the & - either… May 13, 2026 at 8:57 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.