• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Find the inner class

 
Greenhorn
Posts: 10
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I compile this code it outputs PingPong.class , PingPong$MyThread.class and PingPong$1.class
The first and second I understand, but I don't understand why it outputs PingPong$1.class since there is no anonymous inner class. Or is there?..
This is the PingPong.java file:

 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nikolaos Plastiras wrote:When I compile this code it outputs PingPong.class , PingPong$MyThread.class and PingPong$1.class
The first and second I understand, but I don't understand why it outputs PingPong$1.class since there is no anonymous inner class. Or is there?..
This is the PingPong.java file:




Perhaps it is residue from an old incarnation of the class. Did you used to have an anonymous class? If you delete the class files, and recompile again, does it reappear?

Henry
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Perhaps it is residue from an old incarnation of the class. Did you used to have an anonymous class? If you delete the class files, and recompile again, does it reappear?

Henry



I also see these three classes and I just compiled it for the first time.

Regards,
Dan
 
Sheriff
Posts: 28325
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just compiled it and ran it (in Eclipse) and it completed successfully. And I don't see the PingPong$1.class in the compiled classes folder with the other two.

By the way Java 7 is my default runtime. Perhaps this is significant?
 
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw that this class file is created when compiling line 39.

As line 39 and 40 are the same, we can think that one class file has replaced..

And when I delete that class file and run the program, no error was given.

I also want an explanation..
 
Nikolaos Plastiras
Greenhorn
Posts: 10
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I just compiled it and ran it (in Eclipse) and it completed successfully. And I don't see the PingPong$1.class in the compiled classes folder with the other two.

By the way Java 7 is my default runtime. Perhaps this is significant?


I did that too and got two files in bin folder. But did a classic (1.6) javac compilation and got three files!
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nikolaos Plastiras wrote:

Paul Clapham wrote:I just compiled it and ran it (in Eclipse) and it completed successfully. And I don't see the PingPong$1.class in the compiled classes folder with the other two.

By the way Java 7 is my default runtime. Perhaps this is significant?


I did that too and got two files in bin folder. But did a classic (1.6) javac compilation and got three files!




It works for me too (correctly generated two class files). And yes, I compiled with Java 7.

Henry
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting thing - with jdk 1.7.0_04 I see the three classes -



Regards,
Dan

 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic