我有一个带字段的界面.
例如:
public interface InterfaceWithFields {
String field1 = "FIELD_1";
String field2 = "FIELD_2";
}
Run Code Online (Sandbox Code Playgroud)
当我使用Android Studio调试项目时,有时(不是每次) - 我尝试获取字段并返回null -
InterfaceWithFields.field1 /returns null
Run Code Online (Sandbox Code Playgroud)
我认为默认情况下接口中的所有时间字段都是public static final- 它意味着它至少是静态的 - 所以它必须在加载类时立即初始化.
我认为这是Android Studio调试器中的一个错误.
在上面的图像中,当您评估评估器中的字段时,它IConstants.TAG会显示出来null.但是在LogCat中你可以看到它实际上并非如此null.它实际上具有MyApp在LogCat中打印的值.
IConstants.java
public interface IConstants {
String TAG = "MyApp";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
710 次 |
| 最近记录: |