wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Passing an object to a method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing an object to a method." Watch "Passing an object to a method." New topic
Author

Passing an object to a method.

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
I have this question. How this code snippet is allowed to compile.
amethod(new someclass() {} );
How can we have 'Curly Braces' after the constructor name?.
Thank you..


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
It's an anonymous inner class.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
And, as an add-on, this even works for Interfaces.
*spooky* !!
Trent DiBacco
Greenhorn

Joined: May 24, 2002
Posts: 18
and as another add on, this works with anonymous arrays as well.

[ January 11, 2004: Message edited by: Trent DiBacco ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing an object to a method.
 
Similar Threads
signature
mock exam at www.podar.net
I'm using synchronized blocks. Is it valid?
Kanbay or Polaris ?
Info about Infosys Pune