$ in Stacktrace

Discussion in 'Java' started by Christoph, Oct 16, 2006.

  1. Christoph

    Christoph Guest

    Hello,

    i have a simple question. In my stacktrace i often find the signs "$1" or
    "$2" behind a classname, for example:

    "java.lang.ClassCastException: de.gebit.geplan.AllTests$1"

    What does it mean? I couldn´t find any documentation on it.

    Thanks for your help.
    Christoph
    Christoph, Oct 16, 2006
    #1
    1. Advertising

  2. On 16.10.2006 10:40, Christoph wrote:
    > Hello,
    >
    > i have a simple question. In my stacktrace i often find the signs "$1" or
    > "$2" behind a classname, for example:
    >
    > "java.lang.ClassCastException: de.gebit.geplan.AllTests$1"
    >
    > What does it mean? I couldn´t find any documentation on it.


    These are classes that are not explicitly declared like anonymous inner
    classes. When you look into your classpath you'll see them.

    Kind regards

    robert
    Robert Klemme, Oct 16, 2006
    #2
    1. Advertising

  3. Christoph wrote:
    ....
    > ...In my stacktrace i often find the signs "$1" or
    > "$2" behind a classname...

    ....
    > What does it mean?


    There's *gold* in them thar' stacktraces!

    ( OK - see Robert's answer for a technical
    explanation - I just couldn't resist ;)

    Andrew T.
    Andrew Thompson, Oct 16, 2006
    #3
  4. Christoph

    Chris Uppal Guest

    Christoph wrote:

    > "java.lang.ClassCastException: de.gebit.geplan.AllTests$1"
    >
    > What does it mean? I couldn´t find any documentation on it.


    de.gebit.geplan.AllTests$1 is the name of an "anonymous" class defined and used
    somewhere inside de.gebit.geplan.AllTests.

    Java doesn't /really/ have anonymous classes (or any other kind of nested
    class) so the compiler fakes them by creating real classes with made-up names.

    -- chris
    Chris Uppal, Oct 16, 2006
    #4
  5. Christoph schrieb:
    > i have a simple question. In my stacktrace i often find the signs "$1" or
    > "$2" behind a classname, for example:
    >
    > "java.lang.ClassCastException: de.gebit.geplan.AllTests$1"
    >
    > What does it mean? I couldn´t find any documentation on it.

    In addition to what Robert and Chris correctly said:

    Somewhere in your source AllTests.java you have one or more constructs like
    new SomeClassOrInterface()
    {
    ... some methods
    }

    Roughly speaking, the compiler compiles that to
    new AllTests$1(this)
    and generates another class
    class AllTests$1 extends SomeClassOrInterface
    {
    final AllTests this$0;
    Alltests$1(AllTests outerObject)
    {
    this$0 = outerObject;
    }
    ... some methods
    }

    --
    Thomas
    Thomas Fritsch, Oct 16, 2006
    #5
  6. Christoph

    Ian Wilson Guest

    Christoph wrote:
    > Hello,
    >
    > i have a simple question. In my stacktrace i often find the signs "$1" or
    > "$2" behind a classname, for example:
    >
    > "java.lang.ClassCastException: de.gebit.geplan.AllTests$1"
    >
    > What does it mean? I couldn´t find any documentation on it.


    The compiler promotes inner classes to normal classes. IIRC this is so
    that, when you run the application, the JVM doesn't have to do anything
    differently (in this respect) than it did before inner classes were
    added to Java.

    Classes created this way get a name based on the parent's name plus an
    index number plus the inner class name (unless anonymous).
    Ian Wilson, Oct 16, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    703
    S. Justin Gengo
    Aug 5, 2003
  2. Karsten Grombach

    Stacktrace with line numbers

    Karsten Grombach, Aug 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    Tommy
    Aug 8, 2003
  3. Ken Dopierala Jr.
    Replies:
    0
    Views:
    426
    Ken Dopierala Jr.
    Sep 21, 2004
  4. =?Utf-8?B?U3RldmUgS2FsbGFs?=

    StackTrace Line Numbers Missing in ASP.NET deployment...

    =?Utf-8?B?U3RldmUgS2FsbGFs?=, Sep 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,430
    =?Utf-8?B?U3RldmUgS2FsbGFs?=
    Sep 20, 2004
  5. Kieran Toon
    Replies:
    0
    Views:
    439
    Kieran Toon
    Mar 1, 2006
Loading...

Share This Page