Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can a variable with same name present in more than one scope?  RSS feed

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can a variable with same name present in more than one scope?
assume first I declared a variable in page scope and then I declared the same variable in application scope then what happens?
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is YES, but should be in a different scope.

arnel
 
Ashish Sarin
author
Ranch Hand
Posts: 451
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is possible. But it is recommended that you try not to have variables with same name in different scopes. If you do have such a case in which variable with the same name is present in lets say, page and session scopes then when the EL expression is used which requires rearching the various scopes then it will return the variable in the scope which was searched first ie. page.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!