Constants

We define all parameters as constants:

const val GRENADE_DAMAGE : PointsOfDamage = 5L
const val RIFLE_DAMAGE = 3L
const val REGULAR_SPEED : Meters = 1

Those values are very effective, since they are known during compilation.

Unlike static final variables in Java, they cannot be placed inside a class. You should place them either at the top level of your package or nest them inside object.

Note that although Kotlin has type inference, we can specify the types of our constants explicitly, and even use type aliases. How about having DEFAULT_TIMEOUT : Seconds = 60 instead of
DEFAULT_TIMEOUT_SECONDS = 60 in your code? 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179