3. In the Era of Java 1.4
The following is compilable, but ...
public static void main(String[] args) {
List list = new ArrayList();
list.add(23);
String str = (String) list.get(0);
}
4. In the Era of Java 1.4
Implicite upcast from int to Object
public static void main(String[] args) {
List list = new ArrayList();
list.add(23);
String str = (String) list.get(0);
}
5. In the Era of Java 1.4
Downcast from Object to String
public static void main(String[] args) {
List list = new ArrayList();
list.add(23);
String str = (String) list.get(0);
}
6. In the Era of Java 1.4
Run-time exception!!
public static void main(String[] args) {
List list = new ArrayList();
list.add(23);
String str = (String) list.get(0);
}
8. Featherweight Java (FJ)
● Introduced by IGARASHI et al. (2002)
● Formalized & minimalized model
● Many features are omitted, e.g.
○ Assignment
○ Interfaces
○ Exceptions
● “Functional” fragment of Java
9. Three Points to Understand FJ
1. Expressions: What is the “programs”?
2. Typing: What is the “type check”?
3. Reduction: What is the “execution”?
18. Typing Rules
then e0.fi has type Ci under Gamma
Gamma |- e0 : C0
fields(C0) = C1 f1, ..., Cn fn
--------------------------------
Gamma |- e0.fi : Ci
19. Reduction Rules
Example: Rule for field accesses
fields(C) = C1 f1, ..., Cn fn
--------------------------------
(new C(e1, ..., en)).fi -> ei
22. Reduction Rules
If fields of class C are ...
fields(C) = C1 f1, ..., Cn fn
--------------------------------
(new C(e1, ..., en)).fi -> ei
23. Reduction Rules
f1, ..., fn of classes C1, ..., Cn,
fields(C) = C1 f1, ..., Cn fn
--------------------------------
(new C(e1, ..., en)).fi -> ei
24. Reduction Rules
then(new ...).fi reduces to ei
fields(C) = C1 f1, ..., Cn fn
--------------------------------
(new C(e1, ..., en)).fi -> ei
25. “Type Safety” in FJ
If an expression e satisfies:
● e has a type without the two “impolite” rules
● e -> ... -> e’
● No expression e’’ such that e’ -> e’’
Then e’ must be “completely reduced”, i.e.
● e consists of only constructors
26. Summary
● FJ is the “minimum” model of Java
● “Type safety” is the consistency of
○ Typing rules
○ Reduction rules
● We can discuss properties of
programming languages by formalization
27. Have a Nice Typing!
Presented by
Cheshire Cat (@y_taka_23)