I have a Java project, in which I have this Constants class to organise my constants:
/** This is my java constants file in java**/
public class Constants {
public static final String LOWER_GROUND_FLOOR = "LG";
public static final String GROUND_FLOOR = "G";
public static final String FIRST_FLOOR = "1";
public static final String SECOND_FLOOR = "2";
public static final String THIRD_FLOOR = "3";
public static final String THIS_KIOSK_ID = "currentFloorIndex";
public static final String EXPIRY = "cacheExpiry";
public static String third_floor_small_map_path = "map/abc.png";
}
How can I create a similar constants file in Kotlin?
If you want to create a public constant in kotlin like public static final in java, you can create it as follow.
companion object {
const val MY_CONSTANT = "Constants"
}
Checkout this link https://blog.egorand.me/where-do-i-put-my-constants-in-kotlin/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With