Groovy closure inheritance

How does inheritance work in groovy for closure? Is there anything special you need to know about? My application is to expand the plugin controller, which I need to leave alone if there are any updates for it.

+4
source share
1 answer

Inheritance of inheritance does not make much sense (in any case, we tend to use them in any case). Closing in practice is an instance of the Closure class. If we created subclasses of Closure , then we could subclass them, but we won’t. For example, in controllers, we define actions as embedded instances, for example.

 def list = { ... } 

They are considered methods in which we can call list() , but this is just the syntactic sugar for list.call() , since call() is an instance method of the Closure class.

In Grails 2.0, the preferred approach to creating controller actions is to use methods, although closure is still supported for backward compatibility. One of the main reasons for this switch is to support overloading and overriding, which is impossible (or at least practically) using the built-in closures. You can define an instance of the closure in a subclass with the same name as the instance of the base class, but you cannot call super.list() , as this will result in a StackOverflowError

+7
source

All Articles