Skip to content

Commit 3973870

Browse files
committed
add example
1 parent 69aeb3c commit 3973870

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/variableshadowing/VariableShadowingUnitTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class VariableShadowingUnitTest{
7878
}
7979

8080
assertEquals(0, sum)
81+
82+
val lambda = { number : Int ->
83+
val number = 1// Local variable in lambda
84+
}
8185
}
8286

8387
@Test
@@ -162,6 +166,12 @@ class VariableShadowingUnitTest{
162166

163167
assertEquals(0, sum)
164168

169+
numbers.forEach { number ->
170+
sum += number // Directly access the current element in the loop
171+
}
172+
173+
assertEquals(15, sum) // Assuming you want the sum of the original numbers
174+
165175
}
166176

167177
}

0 commit comments

Comments
 (0)