0
How I am able to redefine Val in kotlin in the below program in description? Why does this program works?
In kotlin the function argument is Val by default, but i re initialized the val argument successful inside function body. We can redefine only Var variable. But still this program worked. How? The program is : fun shippingCost(amount: Double, international: Boolean): Double { val amount:Double = when(international){ false -> { if(amount>=75.0) 0.0 else (amount*0.1) } true -> { if((amount*0.15)>50.0) 50.0 else (amount*0.15) } } return amount } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }
1 Réponse
- 1
In this code, the variable (val amount) is defined once, depending on the condition associated with the function argument, which has the same name (amount), about which a warning is displayed.