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
1 answer

Private constructor and final instance variables

If you create a class with uninitialized final variables and a private default constructor, the compiler screams at you that you have uninitialized final variables. That's all well and dandy, except that the constructor is now just unreachable…
Lightfire228
  • 546
  • 1
  • 5
  • 17
0
votes
3 answers

How to use Final Variables belonging to one block in another?

final int a, b; if (condition1) { a = get(dynamicValues); b = get(dynamicValues); } if (condition2) { int c = b + a; display(c); } In this type of code the compiler is asking to intialize a and b, which I can't do until the…
0
votes
2 answers

In swift, what if I mark a property as final

I know if a function is marked as final, then it can't be overridden in subclass. But what if a property in a class is marked as final? I gave it a try and found it can be assigned a new value in subclass.
sevenkplus
  • 178
  • 1
  • 12
0
votes
1 answer

Having problems with redefining variables within an ActionListener

I have this code for a MathFlash Card game. First, it will randomize the numbers from 1 to 12 before the ActionListener is executed since, when the ActionListener is executed, it checks if the answer the user inputted was correct. The…
Zachary Vincze
  • 427
  • 7
  • 24
0
votes
1 answer

How does a private final HashSet Work?

So from my understanding of final you can't change the value of variable after. In the case of a private final foo HashSet<>() = new HashSet<>() I can use foo as a HashSet and edit the values in it but I can't reassign foo right?
ford prefect
  • 7,096
  • 11
  • 56
  • 83
0
votes
3 answers

Please look at the following code. Code is running fine. output is [10,11]. What is the meaning of line final A a = new A();

Please have a look at following code: public class Test { public static void main(String[] s) { final A a = new A(); // What is the meaning of this line ? System.out.println(a.count); a.count…
Chandresh
  • 11
  • 4
0
votes
1 answer

In java 1.8, WTookit class is final. So we can not extend it. Please tell me is there any way to extend this class?

I am using java 1.8. And I came to know that WToolkit is final in java 1.8. But I need to extend this class. Could you please tell me ways to extend this class? I read articles related to javaagent mechanism. If any one knows about agent mechanism,…
0
votes
1 answer

J-Unit Test: Make static void method in final class throw exception

I am writing J-Unit Tests for my project and now this problem occured: I am testing a servlet which uses a Utility class (class is final, all methods are static). The used method returns void and can throw an IOException (httpResponse.getWriter).…
0
votes
1 answer

hql select from final table

Here is my query: update JSNumber set runningNo=(select runningNo +1 from JSNumber where paymentDate= '2015-07-09 00:00:00.0' ) where paymentDate = '2015-07-09 00:00:00.0' This is working fine when I set it to a StringBuilder sb, and run as…
Panadol Chong
  • 1,793
  • 13
  • 54
  • 119
0
votes
2 answers

Overriding a public final static frozen set in Java/Gosu?

I have a set declared static final and is additionally frozen. class MyParent { public final static var MY_FIELDS : Set = { FIELD1, FIELD2, FIELD3, FIELD4, FIELD5 }.freeze() } Now, because the MyParent.MY_FIELD is called…
Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162
0
votes
1 answer

assign byte to Final Integer

Can a variable of type int that has been declared final be assigned to a byte data type variable? Why? public class ByteDataType { public int x=20; byte a=x; //This is an error public final int z=30; byte c=z; …
mRbOneS
  • 121
  • 1
  • 14
0
votes
2 answers

Appropiate way to deal with "final" parameters in Objective-C

I need to "translate" a Java class into Objective-C, and such class has a private final member and an initialization method which receives a final parameter: public class MyClass implements ParentClass { private final OtherClass mOther; …
AppsDev
  • 12,319
  • 23
  • 93
  • 186
0
votes
2 answers

I'm only assigning one value to my final variable but still I'm getting an error

I'm getting an error when making my instance Strings cardRank and cardSuit final and I think that I'm only assigning them values once in my code. I've commented which ones I'm talking about in my code. import java.util.Arrays; public class…
Harout Tatarian
  • 431
  • 4
  • 14
0
votes
0 answers

Cannot refer to the non-final local variable defined in an enclosing scope

So I'm getting the following error in eclipse and I am not understanding what is the problem: ERROR: Cannot refer to the non-final local variable minActiveDutyCycles defined in an enclosing scope The code minActiveDutyCycles[i++]; on line B is…
letter Q
  • 14,735
  • 33
  • 79
  • 118
0
votes
1 answer

LibGDX variable accessed from within inner class

I want to make a method(addButton) that would all what's now done by the constructor, but taking some variables. Now i'm stuck cause there is an error which says that I need to make the boolean final, but I don't want to do that. How should I go…
user4441930