浏览Scala源代码时,我偶然发现了Enumeration.scala
:
abstract class Enumeration(initial: Int, names: String*) extends Serializable {
thisenum =>
def this() = this(0)
def this(names: String*) = this(0, names: _*)
/* Note that `readResolve` cannot be private, since otherwise
the JVM does not invoke it when deserializing subclasses. */
protected def readResolve(): AnyRef = thisenum.getClass.getField("MODULE$").get()
// ... SNIP ...
}
这个 thisenum =>
是用来做什么的?在《Scala编程》书中找不到任何相关信息。
import pygame pygame.init() screen = pygame.display.set_mode((400, 300)) while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: keys = pygame.key.get_pressed() if keys[pygame.K_LSHIFT] and keys[pygame.K_LCTRL]: print("Both Ctrl and Shift are pressed")
在此示例中,我们创建了一个Pygame窗口并循环检查事件。当发生键盘按下事件时,我们使用pygame.key.get_pressed()
方法获取当前按下的所有键,并检查两个特定的键是否都被按下。 - oluies