Hi Alberto, Further to this, all of these have been proposed in one form or another previously during Project Coin during Java 7's development. I suggest you have a look at the old coin-dev archives (http://mail.openjdk.java.net/ pipermail/coin-dev/) to see why they weren't taken on board (or were deferred).
Cheers, Martijn On 4 December 2015 at 18:28, Jonathan Yu <[email protected]> wrote: > Hi Alberto, > > It might be easier to discuss these proposals by separating them into > individual emails, to help keep things focussed. I'm not even sure if this > is the right list for Java language discussions. > > I'm not an expert but just sharing some quick thoughts... > > On Fri, Dec 4, 2015 at 10:22 AM, Alberto Otero RodrÃguez < > [email protected]> wrote: > > > > *3) Switch with blocks* > > > > I think there should be a switch made with blocks in order to permit > > using variables with the same name and avoid the problems of not putting > a > > break. It would be something like: > > > > switch(x) > > { > > case(1) > > { > > int i = 1; > > ... > > } > > case(2) > > { > > int i = 2; > > ... > > } > > default > > { > > ... > > } > > } > > > > This should already be doable today, e.g. > > switch (x) { > case 1: { > int i = 1; > break; > } > case 2: { > int i = 2; > break; > } > > The "break" part is unfortunate but cannot be changed without breaking > existing code, since code that currently falls through would suddenly start > behaving differently. > > > > *4) Multiple condition ternary operator* > > > > I think it would be useful to be able to do this: > > > > String str = condition1 \ condition2 ? stringCondition1 : > > stringCondition2 : stringElse; > > > > > > Instead of: > > > > String str = null; > > if(condition1) > > { > > str = stringCondition1; > > } > > else if(condition2) > > { > > str = stringCondition2; > > }. > > else > > { > > str = stringElse; > > } > > > > Personally, I find even a single ternary operator to sometimes be a bit > hard to follow in code, and I think having multiple like this would be > worse. It can also make stepping through line-by-line in a debugger more > difficult (a reason that I like to use lots of intermediate variables), > even if it results in more lines of code. > > Cheers, > > Jonathan >
