Questions tagged [final]

final is a common keyword specifying that the reference declared as final cannot be modified once it is initialized. In Java the keyword final is roughly equivalent to const in C++. In C++ the final keyword allows you to declare a virtual method, override it N times and then mandate that 'this can no longer be overridden'.

Refer to how the final keyword is used in different programing languages

1662 questions
0
votes
4 answers

Am I using the synchronized block correctly?

I have a SwingWorker which makes calls to the twitter API and gets some results back, everytime a result is received I first update the member variable _latestValidResult, then I take a list of tweets from the result and add it to my list and then I…
Aki K
  • 1,222
  • 1
  • 27
  • 49
0
votes
1 answer

How to save Date object in const variable in java

I created one class : public class CreateAccount { public static Date dNow = new Date(); public static SimpleDateFormat WebsiteURL = new SimpleDateFormat ("E'-'yyyy'-'MM'-'dd'-'hh'-'mm'-'ss'-'a"); public static final String DummyTime =…
Al.s
  • 300
  • 4
  • 20
0
votes
1 answer

Android View.post() method making excessive reference

Sorry I can't come up with a better question title because it's pretty hard to describe... I was inspecting Android's source (4.4 KK), the View class in particular and this showed up: // .... lots of stuff.... AttachInfo mAttachInfo; // .... lots of…
tom91136
  • 8,662
  • 12
  • 58
  • 74
0
votes
1 answer

Image visibility set through handler and function

I need to do setVisibility for an imageview named "heart" through handler and and function get(A). I declared imageview heart as a final variable in the onCreation method and under the class named Another Activity. But whenever I tried to set…
Sungpah Lee
  • 1,003
  • 1
  • 13
  • 31
0
votes
4 answers

Final non-static data member

If you are not allowed to initialize a final non-static data member twice, then how can I set x to something that I want in the following example? class Temp6 { final int x; Temp6() { System.out.println(this.x); …
RAJAN_PARMAR
  • 139
  • 2
  • 9
0
votes
1 answer

Can you write final functions in C#?

I wondered if you can write final (Java) functions/methods in C#. Can I see some examples of C# final functions/methods? There is the opposite question here.
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
0
votes
2 answers

inner class have access to private final methods in base class but why?

Why creators of java allowed this situation? I am sure there must be some reason for it. My below code allows Lion to mischievously run as fast as Cheetah. public class animal { class carnivores { private final void runAsFastAsCheetah()…
instinct
  • 430
  • 1
  • 7
  • 24
0
votes
1 answer

Trying to add ActionListener to a buttonArray

I am not exactly sure what is wrong with my code but, in the process of adding the ActionListeners, I get the error : "local variables referenced from an inner class must be final or effectively final." Appreciate the help :). for (int i = 0; i <…
0
votes
2 answers

Final field, reference and safe publication

Consider the following non-traditional implementation of double-check locking that does not use volatile: public class ValueProvider { private static State state = new Initial(); public static Value getValue() { return state.getValue(); …
AngryJuice
  • 61
  • 1
  • 6
0
votes
1 answer

Why must I use final in this situation?

The situation is like below: import java.io.File; public class FinalTest1 { public static void main(String[] args) { FinalTest1 finalTest1 = new FinalTest1(); finalTest1.test(); } public void test(){ File…
Eugene
  • 10,627
  • 5
  • 49
  • 67
0
votes
2 answers

Automatically initializing an int messageID in a constructor

How can I initialize a final int in the constructor in Java to be with 1 bigger than the previous instance and can I do that at all? I mean i have a final int messageID; which must be unique for every instance, how can I do that?
I.Anchev
  • 83
  • 1
  • 5
0
votes
4 answers

Java compiler/eclipse not reconizing dead code

So I recently came accros this. I was creating an if-else-statement with as it's condition a final boolean variable. Eclipse immediatly told me that the else part of the code was unreachable and therefore dead code. This was my…
Roan
  • 1,200
  • 2
  • 19
  • 32
0
votes
5 answers

Change value of a local variable that needs to be declared final

I have been trying to change the position of my JButton in the action listener. However, when I compiled my code Local variable is accessed from within inner class: needs to be declared final error was displayed. Therefore, I declared my location…
0
votes
1 answer

AWT ActionListener as abstract class

I have a program with a AWT GUI in Java. My problem is that I have a lots of abstract Classes (ActionListener) in this program. Within this abstract classes I need to call attributes from the main-class. So, at the moment I must all needed…
user3302074
0
votes
1 answer

Can setPriority() method be used by a subclass extending Thread class

General Form of setPriority() method is final void setPriority(int level) My question is whether setPriority() method can be used by a subclass extending Thread class since it cannot be overridden because final modifier is set to the…