有没有办法告诉Java或Android中的编译器不要删除代码中的某些语句-这些语句旨在在使用后清理变量以防止ram中的任何数据残留-?创建一个虚拟方法会解决这个问题吗?
这些语句基本上将变量设置为其基于类型的初始值..
提前致谢!
I answer under the odd assumption that you have a good reason to believe that the code is still useful even though it is dead.
Store the value false
in some obfuscated form that the compiler can't understand. Then, conditionally branch to that code using your obfuscated value. The compiler will not know it is dead, so it will not be removed.
I'll use a file for my example, but it is probably not the most efficient way. Say your code that the compiler thinks is dead code was in a function called myCode()
. Assume that fin
is reading from a file that only contains false
followed by EOF
if(Boolean.parseBoolean(fin.next()))
myCode();
您描述的代码不是死代码。死代码是永远不会执行的代码。这是一个例子:
private int secretSchmarr;
public boolean blammo()
{
boolean returnValue;
secretSchmarr = calculateSecretValue();
returnValue = useSecretValue(secretSchmarr);
secretSchmarr = 99; // this is not dead code.
return returnValue;
secretSchmarr = 98; // This is dead code because it can never execute.
}