Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Method Return Issue  RSS feed

 
Nigel Foley
Greenhorn
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an issue trying to return the result from the method below and I am hoping that somebody might be able to spare a little time to assist me.

I have a standard pojo Customer class with three instance variables, constructors, setters and getters



I have created a vector called CustomerVector and populated it with customers.
I want to iterate through the vector to find the customer object that has the same customerId as the int that is passed into the method.



However when I try to return the result the return statement can not see the result String.

Any help to get around this issue would be greatly appreciated

Thanks in advance
Nigel
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your String result is declared inside your if-statement body. When you exit that block on line 7, it goes out of scope and is therefore not available. simply declare it outside the loop:

 
Nigel Foley
Greenhorn
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred,

Thank you very much for the quick accurate response I really apprecriate it,
my issue is now resolved and the method is returning the customer name :-)

Nigel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!