There was an error while loading. Please reload this page.
1 parent e7ecf3e commit 73a4b2cCopy full SHA for 73a4b2c
README.md
@@ -445,6 +445,30 @@ fun doSomething() {
445
}
446
```
447
448
+### Default values for method parameters
449
+> Java
450
+
451
+```java
452
+double calculateCost(int quantity, double pricePerItem) {
453
+ return pricePerItem * quantity;
454
+}
455
456
+double calculateCost(int quantity) {
457
+ // default price is 20.5
458
+ return 20.5 * quantity;
459
460
+```
461
462
+> Kotlin
463
464
+```kotlin
465
+fun calculateCost(quantity: Int, pricePerItem: Double = 20.5) = quantity * pricePerItem
466
467
+calculateCost(10, 25.0) // 250
468
+calculateCost(10) // 205
469
470
471
472
---
473
## Variable number of arguments
474
> Java
0 commit comments