Created
July 13, 2012 08:53
-
-
Save jackywyz/3103747 to your computer and use it in GitHub Desktop.
scala 逆变和协变的判断
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
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