Mostly, I use Int
, Double
and String
, Char
. Recently, I got interested in saving memory and I realized even small amount of bytes can be much larger and it affects the program and even the mobile speed and battery life.(Especially, data resources of its memory)
So, I am trying to use Byte
, Short
when the data doesn't need to store big numbers. For example, byte for -128 ~ 127
, Short for -32,768 ~ 32,767
.
Is it a good idea?
And My main question is I want to know the data type of const val in Kotlin since it automatically defines the datatype.
const val THIS_IS_STRING = "HelloWorld"
const val THIS_IS_CHAR = 'C'
const val NUMBER_1 = -124
const val NUMBER_2 = 31000
const val NUMBER_3 = 1000000
const val NUMBER_4 = 1232188777777344444
const val NUMBER_5 = 29128812312732881231273712
const val NUMBER_6 = 0.423
const val NUMBER_7 = 0.2121222222441
const val NUMBER_8 = 0.813881281237123991827312324
const val NUMBER_9 = 0.5123090982307037412398190092340239423094803820432423423209823092342342348209384023984023480923840923840009930923094029848901
What are the data types of them(The numbers)?
Or should I define like these for saving the resources? Or I don't need to?
const val MIN:Byte = -124
const val MID:Short = 31000
const val MAX:Int = 1000000
...
``