final

Discussion in 'Java' started by Ayrton, Jul 1, 2005.

  1. Ayrton

    Ayrton Guest

    What is the important of this code:
    .....
    fianl JButton ....

    Why final ?

    --
    Questa è una firma automatica di MesNews.
    Sito: http://www.mesnews.net
     
    Ayrton, Jul 1, 2005
    #1
    1. Advertising

  2. On Fri, 01 Jul 2005 17:37:53 +0000, Ayrton wrote:

    > What is the important of this code:
    > ....
    > fianl JButton ....
    >
    > Why final ?


    Because it pleases the dread gods of Javanor...

    Impossible to answer without more code.

    --
    You can't run away forever,
    But there's nothing wrong with getting a good head start.
    --- Jim Steinman, "Rock and Roll Dreams Come Through"
     
    Stefan Schulz, Jul 1, 2005
    #2
    1. Advertising

  3. Ayrton

    Joan Guest

    "Stefan Schulz" <> wrote in message news:p...
    > On Fri, 01 Jul 2005 17:37:53 +0000, Ayrton wrote:
    >
    > > What is the important of this code:
    > > ....
    > > fianl JButton ....
    > >
    > > Why final ?

    Ontologies can validate

    taxonomy membership


    >
    > Because it pleases the dread gods of Javanor...
    >
    > Impossible to answer without more code.
    >
    > --
    > You can't run away forever,
    > But there's nothing wrong with getting a good head start.
    > --- Jim Steinman, "Rock and Roll Dreams Come Through"
    >
    >
     
    Joan, Jul 1, 2005
    #3
  4. Ayrton

    IchBin Guest

    Joan wrote:
    >
    > "Stefan Schulz" < <mailto:>> wrote
    > in message news:p...
    > > On Fri, 01 Jul 2005 17:37:53 +0000, Ayrton wrote:
    > >
    > > > What is the important of this code:
    > > > ....
    > > > fianl JButton ....
    > > >
    > > > Why final ?

    >
    > Ontologies can validate
    >
    > taxonomy membership
    >
    >
    > >
    > > Because it pleases the dread gods of Javanor...
    > >
    > > Impossible to answer without more code.
    > >
    > > --
    > > You can't run away forever,
    > > But there's nothing wrong with getting a good head start.
    > > --- Jim Steinman, "Rock and Roll Dreams Come Through"
    > >
    > >

    >

    As others, you can not tell specifics without more code.

    You can look at The Java Language Specification, Third Edition
    http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

    or The Really Big Index, A list of all content pages in the The JavaTM
    Tutorial
    http://java.sun.com/docs/books/tutorial/reallybigindex.html

    and look up the final modifier.

    --


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    __________________________________________________________________________

    ' If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
     
    IchBin, Jul 2, 2005
    #4
  5. "Ayrton" <> writes:

    > Why final ?


    Why not?
     
    Tor Iver Wilhelmsen, Jul 2, 2005
    #5
  6. In article <>,
    "Ayrton" <> wrote:

    > What is the important of this code:
    > ....
    > fianl JButton ....
    >
    > Why final ?


    The compiler can do some optimizations on final variables, parameters,
    and fields. Final variables make sure that you don't accidentally
    re-assign the value. Final fields make sure that new constructors don't
    forget to provide values. Final fields can make an object immutable so
    it can be safely cached or placed in hash tables.
     
    Kevin McMurtrie, Jul 2, 2005
    #6
  7. Ayrton

    ChrisWSU Guest

    as i understand it...

    say final JButton button = ...
    the value stored in button (reference to the JButton object) is
    constant and cannot be changed. because of this the compiler can use
    certain optimizations. Also since the value is fixed the compiler can
    do certain things with it, that it cannot do with normal references.
    For example.

    public class A {
    public final String s = "a";
    ...
    ...
    public void test(){
    Thread t = new Thread( new Runnable(){
    public void run(){ System.out.println(s);}
    });
    t.start();
    }
    }

    the annoynmous inner class can use the reference. I just wrote that
    out of hat so sry if i missed something. With objects although the
    instance is final, you can still make motifications to that instance,
    but with primitives like ints the value cannot be changed.
     
    ChrisWSU, Jul 2, 2005
    #7
  8. Kevin McMurtrie wrote:
    > In article <>,
    > "Ayrton" <> wrote:
    >
    >
    >>What is the important of this code:
    >>....
    >>fianl JButton ....
    >>
    >>Why final ?

    >
    >
    > The compiler can do some optimizations on final variables, parameters,
    > and fields. Final variables make sure that you don't accidentally
    > re-assign the value. Final fields make sure that new constructors don't
    > forget to provide values. Final fields can make an object immutable so
    > it can be safely cached or placed in hash tables.


    And, considering that we are talking about Swing, it may be relevant
    that final local variables and method parameters can be accessed by
    local inner classes (named or anonymous).

    --
    John Bollinger
     
    John C. Bollinger, Jul 2, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. INFO

    Final Call for Papers

    INFO, Oct 29, 2003, in forum: VHDL
    Replies:
    0
    Views:
    528
  2. avinash
    Replies:
    0
    Views:
    432
    avinash
    Mar 5, 2005
  3. avinash
    Replies:
    0
    Views:
    452
    avinash
    Mar 5, 2005
  4. JFCM
    Replies:
    4
    Views:
    5,754
  5. Replies:
    5
    Views:
    532
    Chris Uppal
    Nov 17, 2006
Loading...

Share This Page