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


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

Re: Enums: Properties vs. Methods

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Enums: Properties vs. Methods
Date Thu, 31 Mar 2011 08:52:58 -0400
Organization albasani.net
Lines 59
Message-ID <in1tev$7bv$1@news.albasani.net> (permalink)
References <2f38bb8e-9a8d-4464-ad3d-b9ce0b557219@e21g2000yqe.googlegroups.com> <h0e4p693s0ioq69bttb88usgq757b7v5eu@4ax.com> <imtgcu$u0g$1@dont-email.me> <imthnl$ckb$1@news.albasani.net> <imting$pcc$1@dont-email.me> <imtojc$q0t$2@news.albasani.net> <imtqlu$u35$1@news.albasani.net> <44ad2578-4baf-4fa9-81b6-3aaa6f458dc7@s11g2000yqh.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net OJdzHGzltuaXxbijpLoTgxdpBU1B0gXn8ZBseHtqAUVHDaORvnLYDDNBWrxVbQH6MI7C8fY98grGHfrrsgFRyA==
NNTP-Posting-Date Thu, 31 Mar 2011 12:52:48 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="XrMUK2jTHLjX0RvvXiHMtp30HYWwusidLS4GFk9ZIsL9/bKe+IQ84zSyCPIDJEIwH9cESO5ZDW+GFOg2nUnG9FCrSPZ141OFeTwFwVCMKDGPcyulig8JssH1EuG58ITV"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8
In-Reply-To <44ad2578-4baf-4fa9-81b6-3aaa6f458dc7@s11g2000yqh.googlegroups.com>
Cancel-Lock sha1:Jc1QMQB8YnNxg31Q3dlGoywwPiM=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2651

Show key headers only | View raw


Robert Klemme wrote:
> You left out an important part of the sentence:
>
> "If a final field is initialized to a compile-time constant IN THE
> FIELD DECLARATION, [...] uses of that final field are replaced at
> compile time with the compile-time constant." (uppercase by me)
> http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.5.3
>
> This is not applicable in the "properties" case because final fields
> are NOT initialized in the field declaration:
>
>    public enum Prop {
>
>      A(true, true), B(true, false), C(false, true);
>
>      private final boolean a;
>
>      private final boolean b;
>
>      Prop(boolean a, boolean b) {
>        this.a = a;
>        this.b = b;
>      }
>
>    // ...
> }

Excellent point.

And yet:

37: tableswitch   { // 3 to 3
                      3: 67
                default: 56
'3' is how it expanded 'kount' in the 'switch' in my example (where 'kount' is 
final and set to 3).

and

public void run();
     Code:
        0: aload_0
        1: getfield      #21  // Field randy:Ljava/util/Random;
        4: iconst_4
        5: invokevirtual #30  // Method java/util/Random.nextInt:(I)I
        8: istore_1

for
  public void run()
  {
    int value = randy.nextInt( kount + 1 );

Note that the compiler DOES replace the reference with a constant.  Looks like 
I was right after all.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

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


Thread

Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-29 08:18 -0700
  Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-29 11:47 -0400
    Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-30 20:00 +0200
      Re: Enums: Properties vs. Methods Lew <lew@lewscanon.com> - 2011-03-30 13:17 -0700
        Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-31 00:48 -0700
          Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-31 08:41 -0400
            Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-31 08:26 -0700
              Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-31 22:16 -0400
                Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-04-02 11:56 +0200
                Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-04-02 10:29 -0400
                Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-04-03 13:14 +0200
  Re: Enums: Properties vs. Methods markspace <-@.> - 2011-03-29 09:26 -0700
    Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-30 20:06 +0200
      Re: Enums: Properties vs. Methods markspace <-@.> - 2011-03-30 12:40 -0700
        Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-31 00:38 -0700
  Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-29 19:03 +0200
    Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-29 19:04 +0200
  Re: Enums: Properties vs. Methods Roedy Green <see_website@mindprod.com.invalid> - 2011-03-29 12:49 -0700
  Re: Enums: Properties vs. Methods Roedy Green <see_website@mindprod.com.invalid> - 2011-03-29 12:52 -0700
    Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-29 22:45 +0200
      Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-29 17:08 -0400
        Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-29 23:25 +0200
          Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-29 19:05 -0400
            Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-29 19:40 -0400
              Re: Enums: Properties vs. Methods Robert Klemme <shortcutter@googlemail.com> - 2011-03-31 02:57 -0700
                Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-31 08:52 -0400
                Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-31 08:54 -0400
            Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-30 18:40 +0200
              Re: Enums: Properties vs. Methods Lew <lew@lewscanon.com> - 2011-03-30 10:33 -0700
                Re: Enums: Properties vs. Methods Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-03-30 20:43 +0200
                Re: Enums: Properties vs. Methods Lew <lew@lewscanon.com> - 2011-03-30 13:20 -0700
                Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-03-31 08:55 -0400
  Re: Enums: Properties vs. Methods Wanja Gayk <brixomatic@yahoo.com> - 2011-04-02 11:23 +0200
    Re: Enums: Properties vs. Methods Lew <noone@lewscanon.com> - 2011-04-02 10:36 -0400
      Re: Enums: Properties vs. Methods Wanja Gayk <brixomatic@yahoo.com> - 2011-04-02 21:20 +0200

csiph-web