文档介绍:Compiling Scala for
the Java Virtual Machine
Michel Schinz
LABORATOIRE DES MÉTHODES DE PROGRAMMATION
INSTITUT D’INFORMATIQUE FONDAMENTALE
FACULTÉ INFORMATIQUE MUNICATION
ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE
Contents
1 Introduction 7
Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Scala programming language . . . . . . . . . . . 8
The Java virtual machine . . . . . . . . . . . . . . . . 9
The piler . . . . . . . . . . . . . . . . . . . . 10
Inheritance graph notation . . . . . . . . . . . . . . . . . . . . 13
2 Mixins 15
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Single inheritance . . . . . . . . . . . . . . . . . . . . . 15
Multiple inheritance . . . . . . . . . . . . . . . . . . . 15
Mixin inheritance . . . . . . . . . . . . . . . . . . . . . 16
Trait inheritance . . . . . . . . . . . . . . . . . . . . . . 16
Mixin inheritance in Scala . . . . . . . . . . . . . . . . . . . . 17
Mixin example . . . . . . . . . . . . . . . . . . . . . . 18
Encoding mixins on the JVM . . . . . . . . . . . . . . . . . . 19
Typing aspect . . . . . . . . . . . . . . . . . . . . . . . 20
Code sharing aspect . . . . . . . . . . . . . . . . . . . 20
Encoding used by scalac . . . . . . . . . . . . . . . . 22
Interfaces for types . . . . . . . . . . . . . . . . . . . . . . . . 25
The AddInterfaces phase . . . . . . . . . . . . . . . . 25
Unmixable classes . . . . . . . . . . . . . . . . . . . . 26
Subclasses of Java classes . . . . . . . . . . . . . . . . 27
Private members . . . . . . . . . . . . . . . . . . . . . 28
Inlining mixin code . . . . . . . . . . . . . . . . . . . . . . . . 29
The ExpandMixins phase . . . . . . . . . . . . . . . . 29
Mixin type parameters . .