Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've just seen this case class in the Scala actors package:

case class ! [a](ch: Channel[a], msg: a)

And in the JavaDoc it describes usage in the following form:

receive {
  case Chan1 ! msg1 => ...
  case Chan2 ! msg2 => ...
}

Why is this not:

receive {
  case !(Chan1, msg1) => ...
  case !(Chan2, msg2) => ...
}

Is the bang operator ! a special case in a similar way to methods ending in a colon :

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
601 views
Welcome To Ask or Share your Answers For Others

1 Answer

When doing pattern matching, the Scala compiler will interpret o1 c1 o2 the same as c1(o1, o2). That's why :: works inside pattern matches too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...