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

Assign values to textview without final string

I got a problem in setting textview values. String ID=""; ......(code to assign ID values) TextView textViewToChange = (TextView) v.findViewById(R.id.textview1); textViewToChange.setText(ID); I got an error that let change ID to final. but the ID…
0
votes
1 answer

Eclipse keep telling me remove final modifier of arraylist

I have a arrayList= new ArrayList(); that is define inside an interface in my Base Activity. public interface RequestUsers { ArrayList arrayList = new ArrayList(); } I already tried…
Mihir
  • 2,064
  • 2
  • 21
  • 28
0
votes
1 answer

final JPanel with added labels (java)

Iam trying to position my jlabel in a jpanel what is made final because of an actionlistener. final JPanel panelPayDetails = new JPanel(); panelPayDetails.setBounds(250, 25, 350, 250); JLabel lblnumber = new JLabel("Insert Number:"); …
user2445977
  • 1
  • 1
  • 2
  • 6
0
votes
0 answers

Android - Cannot be resolved or is not a field

Assume ClassA that define a static final string: public class ClassA implements Serializable { public final static String KeyString = "aKeyString"; And now ClassB trying to use this string: anIntent.putExtra(ClassA.KeyString, anObject); I get an…
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
0
votes
2 answers

Final and Static Final usage in Java

This is from the Ex18 of Chapter "Resuing Classes" in "Thinking in Java". The code is as below: public class E18 { public static void main(String[]args) { System.out.println("First object:"); System.out.println(new WithFinalFields()); …
Kevin
  • 6,711
  • 16
  • 60
  • 107
0
votes
1 answer

Is "final static variables " efficient in Java (Android)?

I'm developing an app in Android. I use a lot "final static" variables to define my constants. But I'm very stric with the memory used by my application. Maybe I have 200 constants (int, string, double, ...). It is much better to program with…
jlmg5564
  • 1,380
  • 13
  • 28
0
votes
2 answers

Unable to setVisible(false) of JFrame

I am creating a Medical Shop Billing software in which I have three JFrames one of which I need to setVisible(false) on the click a JMenuItem. However each time I compile an error is displayed JFrame f is accessed from within inner class; needs to…
Richik Chanda
  • 23
  • 1
  • 7
0
votes
2 answers

Adding ArrayList items to a user-defined class with final values in Java

I have a text file with thousands of lines of data like the following: 38.48,88.25 48.20,98.11 100.24,181.39 83.01,97.33 I can separate each "double" value just fine, but I'm having trouble adding each line to my user-defined class. In my main…
etho201
  • 5
  • 3
0
votes
7 answers

Strange Behavior in final variable in Java

In my java program i have used one final variable.We know that the value of any final variable is fixed and can't be changed.so why this particular program is working fine?Can anyone explain. public static void main(String args[]) { int[]…
Chiradeep
  • 973
  • 12
  • 32
0
votes
2 answers

Is there any performance gain from using final modifier on non-primitive static data?

Is there any performance gain from using final modifier on non-primitive static data in Java? For example: static final Thread t2 = new Thread(new Thread_2()); versus: static Thread t2 = new Thread(new Thread_2()); I mean, static final for…
pdrak
  • 404
  • 1
  • 4
  • 12
0
votes
1 answer

Interface Variables

public interface A { public final int a = 0; } Many books say that all variables (constants) in an interface are implicitly public static final yet when I type the above statement explicitly but do not include the keyword static it compiles…
PragmaticProgrammer
  • 1,079
  • 13
  • 19
0
votes
3 answers

final variable keeps changing but shouldnt

I am engineering a program for my bachelor thesis that displays the inner geometry of a steel wire rope depending on the z location (location in the cable). To test I "walk through" a piece of the cable, with this piece of code (sl is a strand list,…
Jasper
  • 2,389
  • 4
  • 25
  • 40
0
votes
4 answers

java interface static final object equality error

I have a problem. I'm create numeric interface, and I'm create static final object in interface. If I modify the objects and checks the equality, returns true. I overriden the 'equals', the problem is unchanged. Here is the code: public interface…
Resident
  • 11
  • 5
0
votes
2 answers

Java code no longer compiles after factoring out exception throwing to private final function

Have a look at this simple Java code: final class A { public static void main(String[] args) { int x = 3; boolean b; switch(x) { case 1: b = true; break; default: …
Dog
  • 7,707
  • 8
  • 40
  • 74
0
votes
3 answers

Can I acess a final object's methods?

I have to declare a parameter on my method final to access it through a Runnable but can I still access the methods? I need to edit the object a bit. I can't seem to find anything that can help me with this question, so hopefully this isn't a…
1 2 3
99
100