Increasing Java's expressiveness with ThisType and match-bounded polymorphism
暂无分享,去创建一个
In this document we would like to propose some relatively minor additions to Java's syntax and semantics GJS96] in order to increase the expressiveness of the language with little cost in semantic complexity. We avoided making suggestions that would invalidate or change the semantics of programs written in the current version of Java. While the main point of the language extensions are to support parametric polymorphism, we also added features which provide better support for binary methods, a kind of method that is often diicult to support in a statically typed language. (See BCC + 95] for an extensive discussion of the diiculties of statically type-checking binary methods.) Brieey, the changes proposed are to add a \ThisType" 1 construct to represent the type of \this" (the name of the object executing a method), to provide a mechanism for the programmer to specify that a variable hold values of exactly the type given (and not a type that extends it), to reinterpret \extends" as \matching" rather than \subtyping", and to add a form of constrained polymorphism which depends on matching. A more detailed discussion of these constructs and the motivations behind introducing them in typed object-oriented languages can be found in the paper Bru97]. A complete language design including these features can be found in BFP97]. 1 Introducing constrained parametric polymorphism There are many circumstances in which type 2 parameters are useful. For example, when one deenes an array, stack, queue, or tree, the deenitions are written uniformly in the type of value actually stored in the data structure. We propose supporting this by adding an optional type parameter (surrounded by \<>") after interface or class deenitions. We illustrate with a linked list example 3. 1 In my previous work, ThisType was given the name MyType. It was changed here to better correspond to the name this used in Java. In Eiiel, the construct like Current plays a similar role. 2 We will use the word type in this proposal to include class interfaces. 3 We are not completely wedded to the syntax used here. The fact that it is close to what is used for templates in
[1] Kim B. Bruce. Typing in object-oriented languages: Achieving expressiveness and safety , 1996 .
[2] Andrew C. Myers,et al. Parameterized types for Java , 1997, POPL '97.
[3] Kim B. Bruce,et al. Subtyping Is Not a Good "Match" for Object-Oriented Languages , 1997, ECOOP.
[4] Bent Bruun Kristensen,et al. The BETA Programming Language , 1987, Research Directions in Object-Oriented Programming.