Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A类中的static final类型的常量改变了,在B类中不能生效,还是原来的值 #92

Open
GothicFox opened this issue Feb 27, 2018 · 1 comment

Comments

@GothicFox
Copy link

如题,比如最开始编译的时候,A类和B类分别这样的:
`
public class A {
public static final String TAG = "AAA";
}

public class B {

public void printTag(){

System.out.println(A.TAG);

}
}

`

第一次跑的时候 A中的static final 类型的 TAG 是"AAA", 然后修改,如果把A中的static final 类型的 TAG改成 "AAA changed",再重新跑,调用B中的printTag方法时,A中的TAG修改值不生效,还是"AAA"。

fastdex-gradle:0.8.6

com.android.tools.build:gradle:2.0.3

8.0/ 6.0机器都试过

@typ0520
Copy link
Owner

typ0520 commented Feb 28, 2018

这个是一个已知问题,触发这个问题的原因是编译的时候会把引用常量的地方替换成常量的值

public class B {

public void printTag(){

System.out.println(A.TAG);
}
这段代码编译以后会变成下面这样

public class B {

public void printTag(){

System.out.println("AAA");
}

所以当A类的TAG修改成AAA changed的时候,B类引用的还是原来的值AAA, 你可以尝试在B.java中随便加一个换行符让B.java也参与patch就能生效了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants