-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Java ,

, 11 2017 . 14:06 +
Fisfis 14:06

Java ,

, ! A Curious Java Language Feature and How it Produced a Subtle Bug Lukas Eder.

Java . , ?

package p;
 
import static p.A.x;
 
class A {
    static String x = "A.x";
}
 
class B {
    String x = "B.x";
}
 
class C {
    String x = "C.x";
 
    class D extends B {
        void m() {
            System.out.println(x);
        }
    }
}
 
public class X {
    public static void main(String[] args) {
        new C().new D().m();
    }
}

:

B.x

, :

  B      C, ,      ,     A.

?


, . . , , , . , , - ? , , private:

package p;
 
import static p.A.x;
 
class A {
    static String x = "A.x";
}
 
class B {
    private String x = "B.x"; //    
}
 
class C {
    String x = "C.x";
 
    class D extends B {
        void m() {
            System.out.println(x);
        }
    }
}
 
public class X {
    public static void main(String[] args) {
        new C().new D().m();
    }
}

, , B.x m(), . :

  ()   

:

C.x

, :

package p;
 
import static p.A.x;
 
class A {
    static String x = "A.x";
}
 
class B {
    private String x = "B.x";
}
 
class C {
    String xOld = "C.x"; //   
 
    class D extends B {
        void m() {
            System.out.println(x);
        }
    }
}
 
public class X {
    public static void main(String[] args) {
        new C().new D().m();
    }
}

50% , old.

x m() A.x. , :

A.x

,


, , , , , , , .

, - , private. - , .

. , , , , . , , , .


, . final, , , , . , , , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/337648/

:  

: [1] []
 

:
: 

: ( )

:

  URL