|
Groovy example source code file (ClosureDefaultParameterTest.groovy)
The Groovy ClosureDefaultParameterTest.groovy source codepackage groovy /** * @author <a href="mailto:jstrachan@protique.com">James Strachan * @version $Revision: 9213 $ */ class ClosureDefaultParameterTest extends GroovyTestCase { void testClosureWithDefaultParams() { def block = {a = 123, b = 456 -> println "value of a = $a and b = $b" } block = { Integer a = 123, String b = "abc" -> println "value of a = $a and b = $b"; return "$a $b".toString() } assert block.call(456, "def") == "456 def" assert block.call() == "123 abc" assert block(456) == "456 abc" assert block(456, "def") == "456 def" } void testClosureWithDefaultParamFromOuterScope() { def y = 555 def boo = {x = y -> x} assert boo() == y assert boo(1) == 1 } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy ClosureDefaultParameterTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.