Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33286
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: about class dependancies |
| Date | 2015-12-02 21:55 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <n3oauh$pgf$1@speranza.aioe.org> (permalink) |
| References | <565f816b$0$3054$426a74cc@news.free.fr> <77dedcc2-f07c-4234-9b5c-22993b04c6d1@googlegroups.com> <565f9194$0$4565$426a74cc@news.free.fr> <final-20151203020451@ram.dialup.fu-berlin.de> <565f9a2e$0$3878$426a74cc@news.free.fr> |
On 12/2/2015 8:26 PM, regis wrote:
> On 12/03/15 02:05, Stefan Ram wrote:
>> regis <regis.barbanchon@free.fr> writes:
>>> It still seems to work if it is made final...
>>
>> echo >A.java public final class A { public static void main( final
>> java.lang.String[] args ){ java.lang.System.out.println( B.x ); }}
>> echo >B.java public final class B { public static final int x = 1; }
>> javac A.java
>> javac B.java
>> java A
>> RENAME A.class hide.class
>> echo >B.java public final class B { public static final int x = 2; }
>> javac B.java
>> DELETE A.class
>> RENAME hide.class A.class
>> java A
>>
>> Now it still prints 1, not 2.
>>
>> The above script assume Microsoft® Windows.
>> You might have to adjust it for your environment.
>
> Ah, interesting...
> so a non-updated file A.class can indeed be tricked by a change in B...
What is happening is seen with this:
public class B {
public static final int K = 123;
}
public class A {
public static void main(String[] args) {
System.out.println(B.K);
System.out.println(123);
}
}
C:\Work>javap -c A
Compiled from "A.java"
public class A {
public A();
Code:
0: aload_0
1: invokespecial #1 // Method
java/lang/Object."init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2 // Field
java/lang/System.out:Ljava/io/PrintStream;
3: bipush 123
5: invokevirtual #4 // Method
java/io/PrintStream.println:(I)V
8: getstatic #2 // Field
java/lang/System.out:Ljava/io/PrintStream;
11: bipush 123
13: invokevirtual #4 // Method
java/io/PrintStream.println:(I)V
16: return
}
A.class does not contain a named reference to B.K instead
A.class contains the while of B.K from the time of compilation.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
about class dependancies regis <regis.barbanchon@free.fr> - 2015-12-03 00:40 +0100
Re: about class dependancies Lew <lewbloch@gmail.com> - 2015-12-02 16:32 -0800
Re: about class dependancies regis <regis.barbanchon@free.fr> - 2015-12-03 01:49 +0100
Re: about class dependancies regis <regis.barbanchon@free.fr> - 2015-12-03 02:26 +0100
Re: about class dependancies Arne Vajhøj <arne@vajhoej.dk> - 2015-12-02 21:55 -0500
Re: about class dependancies Arne Vajhøj <arne@vajhoej.dk> - 2015-12-02 21:58 -0500
Re: about class dependancies Steven Simpson <ss@my.domain.invalid> - 2015-12-03 15:15 +0000
Re: about class dependancies Arne Vajhøj <arne@vajhoej.dk> - 2015-12-03 19:49 -0500
Re: about class dependancies Lew <lewbloch@gmail.com> - 2015-12-16 18:27 -0800
Re: about class dependancies Steven Simpson <ss@my.domain.invalid> - 2015-12-17 08:39 +0000
Re: about class dependancies Lew <lewbloch@gmail.com> - 2015-12-17 13:36 -0800
Re: about class dependancies Mike Amling <mamling@chaff.us> - 2015-12-21 08:29 -0600
Re: about class dependancies regis <regis.barbanchon@free.fr> - 2015-12-03 02:07 +0100
Re: about class dependancies Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-03 08:06 -0500
csiph-web