问题描述
我会知道在编译时存储全局常量的最佳实践是什么,这些常量可以随环境(debug,preprod,prod,release等)而改变。
在iOS中,我曾经将所有全局常量保存在一个头文件中,并使用预处理器宏对其进行更改,查看此答案: 在哪里存储全局常量在iOS应用程序中?
我应该为Android使用什么解决方案?
在基本包文件夹中创建类常量。
(或者创建一个接口而不是一个类,所以不需要每次都引用这个类,但是这是,但它会工作)
用填充它> public static
此外,类
以及接口
也可以声明为 abstract
。
I would know what is the best practice for storing global constants which can change with the environnement (debug, preprod, prod, release, etc) at compile time.
In iOS, I used to keep all global constants in a header file and change it with pre-processor macro see this answer:
Where to store global constants in an iOS application?
What solution should I use for Android ?
Create a class constants in your base package folder.
(or create an interface instead of a class so there is no need to reference the class everytime, however this is bad practice due to code readability, but it will work)
Fill it with public static final
values.
Moreover, both the class
as well as the interface
can also be declared as abstract
.
这篇关于在Android应用程序中存储全局常量的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!