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

Efficient Adapter implementation

I have in my code two types for Adapter implementations and I'm not sure which one is better. Here is my updater pattern: public View getView(int position, View convertView, ViewGroup parent) { Updater content; if(convertView == null) { …
rekire
  • 47,260
  • 30
  • 167
  • 264
0
votes
2 answers

JavaFX Events Using Local Variables

I have a method that creates an ImageView, called createImageView(), which uses EventHanlders to call vaious events. I would like to be able to use local variables in this method. What I usually do is assign final variables to use within the…
Matt
  • 5,408
  • 14
  • 52
  • 79
0
votes
2 answers

User preferences

I want to make a simple java program that creates a text file at somewhere. I want to let users choose the folder. But when I wrap it in jar file and send to others. Every time my friend runs it, it asks for the folder. I wonder how I can let the…
Fang Li
  • 59
  • 1
  • 1
  • 5
0
votes
2 answers

Set the text of a toast using a position in an array that is the iteration of the loop

This code programatically generates a layout which consists of views and TextViews in a way that is defined in an array. However, I am trying to make each TextView clickable which displays a toast of a bigger explanation of that TextView . Since the…
jackgerrits
  • 791
  • 2
  • 8
  • 20
0
votes
2 answers

Android, change fonts on a final text view

I want to change the font on a text view But the tv is modified at the pression of a button, and i define "final" the tv, and the app crashed... what i can do it? Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/HeroQuest.ttf"); final…
Lele
  • 703
  • 3
  • 15
  • 34
0
votes
5 answers

Difference between final static int and static final int?

Is there any difference between final static int x = 1; and static final int x=1? In other words, will the java compiler represent x in exactly same way in both the cases ? EDIT: Is there any kind of precedence or priority the compiler has with…
Shan
  • 5,054
  • 12
  • 44
  • 58
0
votes
1 answer

Stuck on accessing a non-final variable?

I am just testing out my code and I am trying to make it so when I click the "Push" button, the first textArea prints out "Hello". But I keep getting this error: Cannot refer to a non-final variable textArea inside an inner class defined in a…
Rashesh
  • 15
  • 3
0
votes
2 answers

Final field instead of accessors in enum

Example: public enum TestEnum { FOO(4), BAR(7); public final int externalValue; private TestEnum(int externalValue) { this.externalValue = externalValue; } } Notice how there is no getExternalValue() method. Since the…
TV's Frank
  • 782
  • 7
  • 21
0
votes
2 answers

Disallow call to final parent function in php

I have a parent class that has a public function that is final. Is it possible to disallow access to this method in a derived class? Other classes that derive from the parent class need to still be able to call it. class ParentClass { final…
DudeOnRock
  • 3,685
  • 3
  • 27
  • 58
0
votes
1 answer

Basic java re-factoring: Delegate the differences of child classes to parent and merge/remove them

Please deal with this basic question. I have an abstract class C1 which extends another abstract class C0 and is extended by multiple sub-classes (C21 and C22). @Component public abstract class C0 { protected abstract String getCaller(); …
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85
0
votes
3 answers

Function accessing outside variable

I have a function that iterates over a heavy data set, receives a callback (Google's Guava Function) and runs the callback on every item of the data set: void processData(..., Function callback) { ... for (Item item : data) { …
R S
  • 11,359
  • 10
  • 43
  • 50
0
votes
2 answers

Java - Variable is being accessed from within inner class

IntelliJ wants me to make my variables final, but I need them to change (I will be modifying them within the method). How can I fix this issue? Here is my code, I've never had this issue before: public void openDoor(int id, int x, int y, int face,…
Kuto
  • 21
  • 1
  • 5
0
votes
1 answer

Jar Maker -- Which is the main class?

Alrighty, so I'm working on making a .jar for a client for a little game and I know how to use everything and have done this before, on windows, now i'm on a mac. This shouldn't make a difference but incase you wanted to know, there you go. Now, I…
Sully Brooks
  • 425
  • 4
  • 8
  • 21
0
votes
2 answers

How can i get final string into function for use to another function?

How can I get final string 'data' into this function beginListenForData() for use to another function upload()? BeginListen get data from bluetooth... void beginListenForData() { final Handler handler = new Handler(); workerThread = new…
user1909897
  • 61
  • 4
  • 10
0
votes
2 answers

Why Java Inner Classes require variables of outer class be final?

Possible Duplicate: Java - inner class and local variables How does marking a variable as final allow inner classes to access them? Local Inner class can not only access the instance variables but local variables of the method (in which they are…
Ritesh Kaushik
  • 715
  • 2
  • 13
  • 24
1 2 3
99
100