简体   繁体   English

在静态分析代码时,究竟是什么影子?

[英]What is a shadow exactly, in static analysis of code?

I tried looking for the answer to this! 我试着寻找答案! There are a lot of papers that say about Shadows. 有很多关于阴影的论文。 What is this exactly? 这究竟是什么?

Assuming you are talking about shadowing with names, the Java Language specification says this 假设您正在讨论使用名称进行遮蔽, Java语言规范就是这么说的

Some declarations may be shadowed in part of their scope by another declaration of the same name, in which case a simple name cannot be used to refer to the declared entity. 某些声明可能会在其作用域的一部分中被另一个同名声明所遮蔽,在这种情况下,简单名称不能用于引用声明的实体。

and gives this example 并给出了这个例子

class Test {
    static int x = 1;
    public static void main(String[] args) {
        int x = 0;
        System.out.print("x=" + x);
        System.out.println(", Test.x=" + Test.x);
    }
}

where x is a static class variable and a local variable. 其中xstatic类变量和局部变量。 The local variable will be used if x is referenced in the method the local variable x is defined in. If you wanted to reference the class variable, you would need to use 如果在定义局部变量x的方法中引用了x则将使用局部变量。如果要引用类变量,则需要使用

Test.x

Analysis tools can find things like this. 分析工具可以找到这样的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM