$ 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. Advertisements

  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. Advertisements

  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. Advertisements

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. Karsten Grombach

    Stacktrace with line numbers

    Karsten Grombach, Aug 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    584
    Tommy
    Aug 8, 2003
  2. =?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,670
    =?Utf-8?B?U3RldmUgS2FsbGFs?=
    Sep 20, 2004
  3. Kieran Toon
    Replies:
    0
    Views:
    582
    Kieran Toon
    Mar 1, 2006
  4. Rhino

    Reading Stacktrace in J2ME?

    Rhino, Nov 6, 2004, in forum: Java
    Replies:
    5
    Views:
    6,122
    nagkumar
    Jun 9, 2009
  5. Oliver Brausch

    Stacktrace overflow

    Oliver Brausch, Nov 17, 2004, in forum: Java
    Replies:
    0
    Views:
    426
    Oliver Brausch
    Nov 17, 2004
  6. Timo
    Replies:
    2
    Views:
    419
    Roland
    Feb 7, 2005
  7. Mr Smith
    Replies:
    7
    Views:
    15,217
    Mr Smith
    Feb 21, 2005
  8. Sebastien
    Replies:
    3
    Views:
    9,637
    chinnaswamyg
    Sep 28, 2006
Loading...