简体   繁体   English

Java中是否有类似于Go's Select的关键字或方法?

[英]Any keyword or methods in Java similar to Go's Select?

Java中是否有任何类似于Go的select语句的关键字或方法,仅用于选择通信通道?

The other answers misunderstand the question (or they don't know what select is in Go). 其他答案误解了这个问题(或者他们不知道Go中的select是什么)。

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). Go确实具有一个switch 一个select语句,其中switch与Java的switch大致等效,并且select语句与switch类似,但仅用于进行通信操作时选择(情况是通讯操作: send语句或a 接收操作)。

Java does not have an equivalent to Go's select . Java没有等效于Go的select You can achieve the same but in a more verbose way, and it's not built into the language like Go's select . 您可以实现相同的功能,但方式更为冗长,并且它没有像Go的select这样的语言内置。

See related questions: 查看相关问题:

Concurrency Java example of Go Go的并发Java示例

Equivalent of golang channel in Java 相当于Java中的golang频道

Go channel vs Java BlockingQueue 转到频道与Java BlockingQueue

The similar syntax in Java is switch . Java中类似的语法是switch For detail, you could refer to https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html . 有关详细信息,您可以参考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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM