Is there any keyword or methods in Java that is similar to Go's select statement, that is only used for selection of communication channels?
The other answers misunderstand the question (or they don't know what select
is in Go).
Go does have a switch
and a select
statement, where the switch
is the rough equivalent of Java's switch
, and the select
statement is similar to switch
but only to select on communication operations (the cases are comm. ops.: a send statement or a receive operation).
Java does not have an equivalent to Go's select
. You can achieve the same but in a more verbose way, and it's not built into the language like Go's select
.
See related questions:
Concurrency Java example of Go
The similar syntax in Java is switch. For detail, you could refer to https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html.
switch (month) {
case 1: monthString = "January";
break;
case 2: monthString = "February";
break;
default: monthString = "Invalid month";
break;
}