Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > $ in Stacktrace

Reply
Thread Tools

$ in Stacktrace

 
 
Christoph
Guest
Posts: n/a
 
      10-16-2006
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
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-16-2006
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
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-16-2006
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.

 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      10-16-2006
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



 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      10-16-2006
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
 
Reply With Quote
 
Ian Wilson
Guest
Posts: n/a
 
      10-16-2006
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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
missing line numbers in stacktrace when precompiling Kieran Toon ASP .Net 0 03-01-2006 07:01 PM
Re: StackTrace Line Numbers Missing in ASP.NET deployment... Ken Dopierala Jr. ASP .Net 0 09-21-2004 05:53 PM
StackTrace Line Numbers Missing in ASP.NET deployment... =?Utf-8?B?U3RldmUgS2FsbGFs?= ASP .Net 0 09-20-2004 05:33 PM
Stacktrace with line numbers Karsten Grombach ASP .Net 1 08-08-2003 01:59 AM
Re: Occasionally no line numbers in Exception.StackTrace S. Justin Gengo ASP .Net 0 08-05-2003 08:04 PM



Advertisments