org.eclipse.swt.widgets.Event.type を参照したいのだけど…

org.eclipse.swt.widgets.Event クラスには type という名前のメンバ変数があります。Scala プログラムから type メンバ変数を参照したいのだけど、type は Scala 予約語になっているわけで

    def handleEvent(e: Event) {
      e.type match {
	case SWT.Paint =>
	case SWT.MouseMove =>
	case SWT.Resize =>
	case _ =>
      }
    }

とか書こうとするとエラーになります。探していたら下記ページに解決策がありました。yield で検索していくと見つかります。

プログラミング言語 Scala Wiki - Spec2.8Chap1a

    def handleEvent(e: Event) {
      e.`type` match {
	case SWT.Paint =>
	case SWT.MouseMove =>
	case SWT.Resize =>
	case _ =>
      }
    }

のように、バッククオートで囲むことで回避できました。

Version Info