mardi 21 janvier 2020

Why can you call some methods without parentheses while for others you must use parentheses (Kotlin)?

In the example below, why is it that I can invoke nums.lastIndex WITHOUT using parentheses (ex. nums.lastIndex) while for nums.isEmpty() I need to use parentheses?

fun removeDuplicates(nums: IntArray): Int {
    if(nums.isEmpty()) return 0
    var forwardCounter = 0
    var newArrayIndex = 0
    while(forwardCounter != nums.lastIndex) {
        if(nums[newArrayIndex] < nums[forwardCounter + 1]) {
            newArrayIndex += 1
            nums[newArrayIndex] = nums[forwardCounter + 1]
        }
    forwardCounter += 1
    }
    return newArrayIndex + 1
}



Aucun commentaire:

Enregistrer un commentaire