Danish Ansari
12/02/2021, 2:52 PMRichard Gomez
12/02/2021, 3:05 PMDanish Ansari
12/02/2021, 3:07 PMPaul Griffith
12/02/2021, 3:15 PMval label1 = JLabel()
val label2 = JLabel()
label1.text = "label1"
label1.icon = null
label1.horizontalAlignment = SwingConstants.HORIZONTAL
label2.text = "label2"
label2.icon = null
label2.horizontalAlignment = SwingConstants.HORIZONTAL
You're constantly repeating label1
and label2
, your modifications of the object aren't 'attached' to the initialization, etcFleshgrinder
12/02/2021, 3:21 PMsomeMap.forEach { (k, v) -> }
Here both k
and v
are only available within the scope of forEach {}
, not before, not after. There are no questions regarding what value k
or v
has after the loop concludes. Compare this with the following (pseudo-code):
for (i = 0; i < x; ++i) {}
println(i)
In some languages this actually works because i
leaks since it’s not scoped to only the loop.Fleshgrinder
12/02/2021, 3:24 PMDanish Ansari
12/02/2021, 3:46 PMDominaezzz
12/02/2021, 4:24 PMDanish Ansari
12/02/2021, 4:38 PMAstronaut4449
12/03/2021, 7:32 PMAstronaut4449
12/03/2021, 7:41 PMAstronaut4449
12/03/2021, 7:42 PMAstronaut4449
12/03/2021, 7:44 PMDominaezzz
12/03/2021, 7:46 PMit
is sometimes more readable that superContextualLongVariableName
. Otherwise, overuse can make code trickier to read, especially with ?.
and ?:
.Astronaut4449
12/03/2021, 7:48 PMArrays.asList()
method to create a list.