Skip to content

Instantly share code, notes, and snippets.

@jackywyz
Created July 13, 2012 08:53
Show Gist options
  • Save jackywyz/3103747 to your computer and use it in GitHub Desktop.
Save jackywyz/3103747 to your computer and use it in GitHub Desktop.
scala 逆变和协变的判断
import scala.util.control.Breaks._
object Continued extends scala.util.control.Breaks {}
import Continued.{break=>continue, breakable=>continuing}
// Now every time you need it:
breakable{ for (i <- 1 to 10) continuing {
if ((i%2)==0) continue
if (i>3) break
println(i)
}}
//
trait T[-A,+B] {val name:B ;def say(a:A,b:B=>A):B = name}
//说明:
/*
因为Function1[-P,+R] ,所以方法参数是-值,而返回值和参数类型是+值。
当给方法的类型标上+/-后,需要符合[-A,+B]:
so, name:B+ -> +B
a:A- -> -A
b:(B-=>A+)- => +B , -A
都满足了。
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment