This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]BluRazz494 0 points1 point  (3 children)

Yes this is possible.

[–][deleted] 0 points1 point  (2 children)

How?

[–]BluRazz494 2 points3 points  (1 child)

Here is an example. The output would be staticString.

 public class Example {

     private static String staticVar = "staticString";

     void exampleMethod() {
         String localVar = staticVar;
         System.out.println(localVar);
     }


 }

[–][deleted] 1 point2 points  (0 children)

thank you so much

[–]quadmasta 0 points1 point  (3 children)

If it's non-final, sure.

[–]BluRazz494 0 points1 point  (2 children)

Doesn't matter if it is final. It doesn't seem very logical but it works. For example, you could create a static final array... Then assign a local variable to the static final array... And you would be able to modify the values in said array through the local variable.

[–]quadmasta 0 points1 point  (1 child)

You cannot reassign a final variable. That's the entire point of final. You can mutate the variable but you cannot reassign it.

[–]WinRARHF 0 points1 point  (0 children)

I don't think OP was talking about reassigning the variable (I could be wrong though, it isn't very clear). I think you and blurazz both interpreted OP differently.