final

S

Stefan Schulz

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.
 
I

IchBin

Joan said:
Ontologies can validate

taxonomy membership
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-)
 
K

Kevin McMurtrie

Ayrton said:
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.
 
C

ChrisWSU

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.
 
J

John C. Bollinger

Kevin said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top