Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sometimes .java compiles to two class files

Reply
Thread Tools

Sometimes .java compiles to two class files

 
 
Mythic Wave
Guest
Posts: n/a
 
      08-18-2005
Hello,

Sometimes when I compile a long .java file, I get two class files as a
result. For example, the file servlet.java compiles to servlet.class and
servlet$1.class. Does anyone know why the servlet$1.class file is created
and how to control it?

Thanks,

Brian




 
Reply With Quote
 
 
 
 
Nicholas Clarke
Guest
Posts: n/a
 
      08-18-2005
On Thu, 18 Aug 2005, Mythic Wave wrote:

> Sometimes when I compile a long .java file, I get two class files as a
> result. For example, the file servlet.java compiles to servlet.class and
> servlet$1.class. Does anyone know why the servlet$1.class file is created
> and how to control it?


$1,2... are anonymous inner classes. I doubt you can control it besides
not using inner classes.

-Nicholas

 
Reply With Quote
 
 
 
 
Daniel Cer
Guest
Posts: n/a
 
      08-18-2005
> Hello,
>
> Sometimes when I compile a long .java file, I get two class files as a
> result. For example, the file servlet.java compiles to servlet.class and
> servlet$1.class. Does anyone know why the servlet$1.class file is created
> and how to control it?
>
> Thanks,
>
> Brian


It looks like you have an anonymous inner class somewhere in the source file.

Grep for something like

Object someRandomName = new Object() { ...

The 'servlet$1.class' file is just the byte-code for the compiled inner
class.

-Dan
 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      08-18-2005
"Mythic Wave" <> said:
>Sometimes when I compile a long .java file, I get two class files as a
>result. For example, the file servlet.java compiles to servlet.class and
>servlet$1.class. Does anyone know why the servlet$1.class file is created
>and how to control it?


It's not the length. It's that you have an anonymous inner class in
your code. If a single source file contains more than one anonymous
inner classes, you'll get Foo$2.class, Foo$3.class, ... .

See:
http://mindprod.com/jgloss/innerclasses.html
http://mindprod.com/jgloss/anonymousclasses.html
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
Mythic Wave
Guest
Posts: n/a
 
      08-18-2005
Yes, an inner class was there. Thanks.

Brian

"Mythic Wave" <> wrote in message
news:...
> Hello,
>
> Sometimes when I compile a long .java file, I get two class files as a
> result. For example, the file servlet.java compiles to servlet.class and
> servlet$1.class. Does anyone know why the servlet$1.class file is created
> and how to control it?
>
> Thanks,
>
> Brian
>
>
>
>



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-18-2005
On Thu, 18 Aug 2005 09:50:35 -0700, "Mythic Wave"
<> wrote or quoted :

>Sometimes when I compile a long .java file, I get two class files as a
>result. For example, the file servlet.java compiles to servlet.class and
>servlet$1.class. Does anyone know why the servlet$1.class file is created
>and how to control it?


it is typically an anonymous inner class. If you don't like them,
name your classes.
 
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
OT: I find... sometimes it's easy to be myself... sometimes... I find it's better to be somebody else. The Obelisk [7.13.86.42] MCSE 10 06-04-2006 05:40 AM
Firefox locks up on first URL sometimes; Sometimes closes itself Jim Firefox 0 06-28-2005 01:42 PM
? Content Entered in Forms Sometimes Duplicated and Sometimes Not ? Nehmo Sergheyev HTML 1 05-09-2004 07:07 PM
::std sometimes needed, sometimes not Marcin Vorbrodt C++ 24 09-17-2003 03:01 PM
Re: Sometimes ASP.NET does find the dll, sometimes doesn't John Saunders ASP .Net 0 08-28-2003 01:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57