Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

declaring variables inside loops

802323Oct 5 2010 — edited Oct 5 2010
quite lost with this topic because I've read a thousand different opinions.

given the code:
for (MyClass myObject : myList<MyClass>) {
     String name = myObject.getName();
     long time = myObject.getTime();
     doWhateverWith(name, time);
}
Should I put declarations outside? Nowadays, in which situations would it make a difference?

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2010
Added on Oct 5 2010
5 comments
727 views