зеркало из
				https://github.com/iharh/notes.git
				synced 2025-10-30 21:26:09 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			31 строка
		
	
	
		
			466 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			31 строка
		
	
	
		
			466 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| class Foo {
 | |
|     def target
 | |
| }
 | |
| 
 | |
| class Bar {
 | |
|     Foo foo = new Foo()
 | |
|     void do something (Closure c) {
 | |
|         c.delegate = foo
 | |
|         c()
 | |
|     }
 | |
| }
 | |
| 
 | |
| Bar bar = new Bar()
 | |
| bar.dosomething {
 | |
|     target = 10
 | |
| }
 | |
| 
 | |
| // If a groovy class has a method call(Closure), the object can be passed a closure directly
 | |
| 
 | |
| class Foo {
 | |
|     def call(Closure c) { ... }
 | |
| }
 | |
| 
 | |
| Foo foo = new Foo()
 | |
| foo {
 | |
|     println 'Hello, world'
 | |
| }
 | |
| 
 | |
| // This avoids ugly syntax
 | |
| foo.call({ println 'Hello, world' })
 | 
