Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the good practice to create a Constants file in kotlin [closed]

Tags:

android

kotlin

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?

like image 299
mandar bhoot Avatar asked Dec 01 '25 13:12

mandar bhoot


1 Answers

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/

like image 162
Lakshmi Avatar answered Dec 04 '25 05:12

Lakshmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!