|
Groovy example source code file (MultipleAssignmentTest.groovy)
The Groovy MultipleAssignmentTest.groovy source code
package gls.statements
import gls.CompilableTestSupport
class MultipleAssignmentTest extends CompilableTestSupport {
void testList() {
def list = [1, 2]
def a, b
(a, b) = list
assert a == 1
assert b == 2
(a, b) = [3, 4]
assert a == 3
assert b == 4
}
void testArray() {
def array = [1, 2] as int[]
def a, b
(a, b) = array
assert a == 1
assert b == 2
}
def foo() {[1, 2]}
void testMethod() {
def a, b
(a, b) = foo()
assert a == 1
assert b == 2
}
void testMethodOverflow() {
def a, b = 3
(a) = foo()
assert a == 1
assert b == 3
}
void testMethodUnderflow() {
def a, b, c = 4
(a, b, c) = foo()
assert a == 1
assert b == 2
assert c == null
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy MultipleAssignmentTest.groovy source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.