0

I need a way to write R1 or R[1] and refer to the same variable.

2
  • 2
    Without more context: Object R1 = R[1]; Commented Jul 9, 2012 at 4:48
  • 1
    And what do you need this for? Commented Jul 9, 2012 at 4:52

1 Answer 1

1

If you're trying to use the general pattern of having ALPHANUMBER and ALPHA[NUMBER] refer to the same variable, you can't do it. The square bracket notation in Java refers to an element in an array, while the first is just a general identifier that can refer to a variable.

In the specific case of creating two variables, one a direct reference and the other an element in an array, you can simply point r[1] = r1 (as long as r1 has been initialized).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.