我有一个Java项目,其中有一个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";
}
如何在Kotlin中创建类似的常量文件?
答案 0 :(得分:1)
如果要像在Java中创建public static final一样在kotlin中创建一个公共常量,则可以按以下步骤创建它。
companion object {
const val MY_CONSTANT = "Constants"
}
签出此链接 https://blog.egorand.me/where-do-i-put-my-constants-in-kotlin/