Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static final array

 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can arrays be static and final?
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Miki,

I see no problems there. You can definately declare an array as final and static both.

If you are having a problem somewhere in a program, I guess it might be because you are either declaring the array inside a static context, or may be you are trying to change the reference of this array .

I am writing a code here :


This will give you a compilation error because you are trying to change the reference value of the array that has been declared as "final". This is illegal.

however, in the following code :




there is no problem here. This code compiles and prints the output :



so, the moral of the story is : "when you declare an array as final, you can change the elements in the array, however you cannot change the reference of this array."

Hope it helps you

All the best
 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You for your reply.It cleared my confusion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic