Thread: Anonymous Code
View Single Post
Old 01-14-2013, 02:45 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yeah, this is an anonymous inner class. ActionListener itself is an interface, but since it is being invoked and the entire method set is being declared as a part of the class body, this is valid code. Prior to Java 8, it's also the closest thing we have to a closure in Java.
So effectively you create an unnamed instance and provide that as the argument. That particular instance can never be used again.
Fou-Lu is offline   Reply With Quote