Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33379

Re: about class dependancies

From Mike Amling <mamling@chaff.us>
Newsgroups comp.lang.java.programmer
Subject Re: about class dependancies
Date 2015-12-21 08:29 -0600
Organization A noiseless patient Spider
Message-ID <n59255$6ve$1@dont-email.me> (permalink)
References (1 earlier) <77dedcc2-f07c-4234-9b5c-22993b04c6d1@googlegroups.com> <565f9194$0$4565$426a74cc@news.free.fr> <31f29220-8f05-42a4-b62e-59eec378b924@googlegroups.com> <bu8akc-reu.ln1@s.simpson148.btinternet.com> <5fa6a8a6-389b-4ed0-ae37-941d5fd6d358@googlegroups.com>

Show all headers | View raw


On 12/17/15 3:36 PM, Lew wrote:
>
> You define a constant variable in B and refer to it from A.
>
> You recompile B with a different constant value.
>
> You then run A without recompiling it. Magically, it refers to the old value of the B constant.
>
> Because the constant was inlined in A, it stopped looking like a variable, so the runtime linkage doesn't refer to the constant from B, but uses the inlined value already in A.
> http://javasplitter.blogspot.com/2011/10/static-final-inline-trap.html

I've seen Java software use this to ensure that the components in use 
are consistent. E.g.,

class A {
  public static final int VERSION=3;
  public int getVersion() {
    return VERSION;
  }
}

class B {
  public static void main(String[] args) {
    if (A.getVersion()  // The version we're running with
     !=A.VERSION) {  // The version we were compiled with
      uhoh();
    }
  }
}

Mike Amling
--
QnV0IEkgZG9uJ3QgcmVjYWxsIHdoYXQgcHJvZ3JhbSBJIHNhdyB0aGlzIGluLg==

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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