最好的办法,包括调试code?最好的、办法、code

2023-09-04 08:39:09 作者:宿命中妥协

我编程Android应用,并在这里的最佳方式可以是或可以不是相同的Java一般

I am programming Android applications, and the best way here may or may not be the same as Java in general.

我只是希望能够设置调试标志,将只执行了code某部分时,它被设置为真 - 当量为C ++设置preprocessor的#define调试和使用的#ifdef DEBUG。

I simply want to be able to set a debug flag that will only execute certain portions of code when it's set to true––equiv to C++ setting a preprocessor #define DEBUG and using #ifdef DEBUG.

有没有一个公认的或最好的方式做到这一点在Java中?

Is there an accepted or best way to accomplish this in Java?

现在我只是要设置在我的应用程序对象的变量,但我不想象这是最好的方式。

Right now I'm just going to set a variable in my Application object, but I don't imagine this is the best way.

推荐答案

这是我做的方式:

// in some.class.with.Constants
public static final boolean DEV_MODE = true;

// in some other class
import static some.class.with.Constants.DEV_MODE;

if(DEV_MODE){
    Log.d('sometag', 'somemessage');
}