Stephan van Hulst wrote:It's hard for the compiler to determine that an opening brace in a spot where any expression may occur (such as the right hand of the return keyword) is not the start of a new scope.
Which suggests that maybe Java should have used a different "bracket" for initialisers.
@Shubham Rai: A lot of this comes down to the fact that, way back in the '80s, Java was designed to "look" like C and C++, so that programmers would have less of a learning curve when learning the language.
As you can see, that comes with some trade-offs that aren't always wonderful. :-)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
The similarity of Java® syntax to C/C++ has also caused lots of confusion to people coming from C++, but some people have said they wouldn't have started using Java® if it had looked different from the older languages.
You've gotta fight it! Don't give in! Read this tiny ad:
global solutions you can do at home or in your backyard