bdw429s
09/28/2022, 6:32 PMswitch(5) {
case 'foo':
break;
break;
}
The error is Only case: or default: statements may be immediately contained by a switch statement.
which makes sense (there is an extra break;
. So, should it error? Should the message be any different? Just curious what your take is on it.bdw429s
09/28/2022, 6:32 PMAdam Cameron
Adam Cameron
switch(5) {
console.log("hi")
case 'foo':
break;
break;
}
VM150:2 Uncaught SyntaxError: Unexpected identifier 'console'
switch(5) {
case 'foo':
break;
break;
console.log("hi")
}
undefined
Adam Cameron
Adam Cameron
case
statement could be considered "everything until the next case
, the default
, or the end of the switch
I guess. This looks to be what JS & PHP are doingAdam Cameron
Adam Cameron
class TestSwitch {
public static void main(String[] args) {
switch ("notfoo") {
case "foo":
break;
break;
}
}
}
TestSwitch.java:8: error: unreachable statement
break;
^
1 error
Adam Cameron
seancorfield
jshell> switch ( 42 ) {
...> case 1: break;
...> case 2: break;
...> break;
...> }
| Error:
| unreachable statement
| break;
| ^----^
| Error:
| missing return statement
| switch ( 42 ) {
| ^--------------...
Adam Cameron
seancorfield
Adam Cameron
seancorfield
seanc@Sean-win-11-laptop:~$ jshell
| Welcome to JShell -- Version 19
| For an introduction type: /help intro
🙂 With --enable-preview
(at least on the JDK) you can get virtual threads!Adam Cameron
TestXxx
classes like the above I have created over the years... I don't know 😕Adam Cameron
seancorfield
seanc@Sean-win-11-laptop:~$ jshell --enable-preview
| Welcome to JShell -- Version 19
| For an introduction type: /help intro
jshell> java.lang.Thread.startVirtualThread( () -> { System.out.println("Hi! I'm virtual!");} );
Hi! I'm virtual!
$1 ==> VirtualThread[#25]/runnable
jshell>
(compared to the Clojure code: (Thread/startVirtualThread #(println "Hi! I'm virtual!"))
-- gods, I hate Java!!seancorfield
Adam Cameron
seancorfield
jshell
was added in Java 9 so it's not exactly "new"...seancorfield
Adam Cameron
seancorfield
seancorfield
mtbrown
09/29/2022, 2:18 PMbreak
breaks out of that case
. So it's looking for the next case
or default
in the switch
, but encounters something else. It gives the same error for any statement.bdw429s
09/29/2022, 3:10 PMEvil Ware
09/29/2022, 10:58 PMbdw429s
09/30/2022, 3:09 PM