• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local Class

 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When the above code is executed the CTOR doesn't get printed. Can any one explain?
 
Tom Adams
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think all you need to do is put the local class definition (c1 class) before the
c1 c123 = new c1();
line. At least that worked for me. I actually received a compiler error on the original source. Which I think is called a forward reference error(?).
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarma,
The code you posted does not compile on my machine:
Try this code:
 
Dan Culache
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maria, I believe Tom's explanation is correct.
Your code refers to regular inner classes and Sarma's code refers to method-local inner classes.
So it looks like when you define a method-local inner class you cannot forward reference it like you can with a regular inner class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic