aspose file tools*
The moose likes Beginning Java and the fly likes why we get away with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why we get away with this?" Watch "why we get away with this?" New topic
Author

why we get away with this?

f. nikita thomas
Ranch Hand

Joined: Mar 02, 2008
Posts: 87
i didn't know braces were allowed inside method declarations:




[edit]Delete excess whitespace. CR[/edit]
[ October 21, 2008: Message edited by: Campbell Ritchie ]

Imagination is more important than knowledge "Albert Einstein"
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
I assume you mean this?



Its creating an anonymous inner class that is a Runnable.

[ October 21, 2008: Message edited by: Paul Beckett ]
[edit]Delete excess whitespace. CR[/edit]
[ October 21, 2008: Message edited by: Campbell Ritchie ]
f. nikita thomas
Ranch Hand

Joined: Mar 02, 2008
Posts: 87
kewl. i just googled it. thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Well done, but please spell cool cool not kewl: see this FAQ. And please set up your text editor to convert tabs to 4 spaces each; your original post was falling off the end of the screen with all the long tabs.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14268
    
  21

The example you gave was indeed an anonymous inner class (that implements the interface Runnable). But besides that, it is possible to put arbitrary statements inside a method in a pair of { and }:

Note that in this example, the scope of the variable i is limited to the block.

Being able to create arbitrary blocks like this is an interesting feature, but I wouldn't use this in my own Java programs, because it's not something that's commonly done and it might confuse other developers that would read my code, and it's not something that's really very useful.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why we get away with this?