Is there any significant performance problems between the two code snippets ?
User user
for(int i =0 ; i < 100 ; i++) {
user = new User() ;
}
and
for(int i =0 ; i < 100 ; i++) {
User user = new User() ;
}
It’s just about declaration.
There is a myth out there that this does make a difference, but the Java compiler is smart enough to make sure that it doesn’t. This blog and this blog show the generated byte code between the two types of declarations. There isn’t a significant performance difference.
The difference is what you find more readable.