Advances in Programming Languages: Generics, Interoperability and Implementation

Total Page:16

File Type:pdf, Size:1020Kb

Advances in Programming Languages: Generics, Interoperability and Implementation Advances in Programming Languages: Generics, interoperability and implementation Stephen Gilmore The University of Edinburgh February 1, 2007 Understanding generic code Generic Java extends Java with generic type variables which allow us to define generic classes and generic methods. Generic C# extends C# similarly. When adding genericity to an object- oriented programming language it is important to do this in a way which does not invalidate existing code. Legacy code (which does not use the generic features of the language) should continue to operate as before and there should be a smooth upgrade path from legacy code to generic code. In Generic Java (Java 1.5) generics are compiled out by the Java compiler. Type variables are replaced by Object and downcasts are inserted automatically by the compiler instead of being coded manually by the programmer. The implications of this are that generic code is never slower than non-generic code (but there is no reason to think that it will be faster) while being more reliable than non-generic code. The way-ahead-of-time optimising compiler gcj will be extended to deal with Java generics when GCC-4.3 is released. The gcj compiler will include the Eclipse Compiler for Java, ecj as its front-end. This extended gcj could produce faster code by eliminating casts. This example shows use of SUN’s javac. /* File: programs/java/Cell.java */ /* A generic, updateable cell */ class Cell<A> { A value; Cell(A value) { this.value = value; } A get() { return value; } void set (A value) { this.value = value; } } The above example is a simple generic cell which holds values. We now try comparing that generic Java class with its compiled bytecode representation. We can inspect the Java bytecode produced by the compiler by using the Java disassembler javap. We use the command javap -c Cell When compiled to Java bytecode we see that the cell is operating on objects of class java.lang.Object. 1 UG4 Advances in Programming Languages — 2005/2006 2 Compiled from "Cell.java" class Cell extends java.lang.Object{ java.lang.Object value; Cell(java.lang.Object); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: aload_1 6: putfield #2; //Field value:Ljava/lang/Object; 9: return java.lang.Object get(); Code: 0: aload_0 1: getfield #2; //Field value:Ljava/lang/Object; 4: areturn void set(java.lang.Object); Code: 0: aload_0 1: aload_1 2: putfield #2; //Field value:Ljava/lang/Object; 5: return } That was an example of how generic classes are defined. How are they used? /* File: programs/java/CellTest.java */ class CellTest { public static void main (String[] args) { Cell<String> sc1 = new Cell<String>("First"); String s1 = sc1.get(); /* No cast needed */ System.out.println(s1); } } As usual with generic classes, a cast is not written by the application developer, but it is automatically inserted by the compiler. Compiled from "CellTest.java" class CellTest extends java.lang.Object{ CellTest(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); UG4 Advances in Programming Languages — 2005/2006 3 Code: 0: new #2; //class Cell 3: dup 4: ldc #3; //String First 6: invokespecial #4; //Method Cell."<init>":(Ljava/lang/Object;)V 9: astore_1 10: aload_1 11: invokevirtual #5; //Method Cell.get:()Ljava/lang/Object; 14: checkcast #6; //class String 17: astore_2 18: getstatic #7; //Field java/lang/System.out:Ljava/io/PrintStream; 21: aload_2 22: invokevirtual #8; //Method java/io/PrintStream.println:(Ljava/lang/String;)V 25: return } Perhaps the overriding motivation for taking this approach to implementing generics in Java is that the Java Virtual Machine should be unaffected by this approach. From the JVM point of view the bytecode which it executes would look just like it came from a (typesafe) object polymorphic method. Because many manufacturers have implemented Java Virtual Machines it was a sensible design constraint to contain this change to the Java language within the compiler. Unfortunately SUN’s Java 1.5 compiler does not correctly fulfil the intended design because it compiles only for the 1.5 virtual machine, not for earlier ones. This largely undermines the approach of compilation by erasure and means that generics could have been supported in the JVM. A separate tool, Retroweaver, can convert Java 1.5 and higher class files to Java 1.4, 1.3 or 1.2, but depending on a third-party tool to repair the compiled class files is not attractive to most developers. We demonstrate how the problem is experienced by users trying to run modern bytecode on older JVMs. [scap]stg: export ALT=/etc/alternatives [scap]stg: alias java6c=$ALT/java_sdk_1.6.0/bin/javac [scap]stg: java6c -version javac 1.6.0 [scap]stg: java6c GenericStack.java [scap]stg: alias java4=$ALT/jre_1.4.2/bin/java [beetgreens]stg: java4 -version java version "1.4.2" gij (GNU libgcj) version 4.1.1 20060525 (Red Hat 4.1.1-1) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [scap]stg: java4 GenericStack Exception in thread "main" java.lang.ClassFormatError: GenericStack (unrecognized class file version) An alternative is to ask the Java compiler to generate Java 1.4 compliant bytecode. [scap]stg: java6c GenericStack.java [scap]stg: file GenericStack.class UG4 Advances in Programming Languages — 2005/2006 4 GenericStack.class: compiled Java class data, version 50.0 [scap]stg: java6c -target jsr14 GenericStack.java [scap]stg: file GenericStack.class GenericStack.class: compiled Java class data, version 48.0 [scap]stg: java4 GenericStack c b a Unfortunately it transpires that this use of the target flag is not recommended by the SUN compiler developers. I should not mention the javac flag ”-target jsr14”, which causes javac to gen- erate maximally-1.4-compatible code with the new language features enabled. That flag is useful for bootstrapping and testing javac, but you should not depend on it. If it doesn’t work as you want and you report a bug about it, you can expect the flag to be removed. Neal Gafter, SUN lead Java compiler developer Some of the complications are that, because of separate compilation, it is necessary for class files to carry generic type variable information. This is added to the metadata in the class file, specifically as a new “Signature” attribute for classes, methods and fields. Generics in C# are supported down into the Common Language Runtime, thus their im- plementation does not have the impact on typing which erasure does and can improve the performance of compiled code by removing casts and unnecessary “boxing” (compilation by erasure does not give any performance improvement). Polymorphic classes in Objective Caml Generic Java allows developers to parameterise classes by a generic class variable—the param- eter must be a reference type, not one of the built-in ground types (such as int, boolean, float or double). Polymorphic classes in Objective Caml are parameterised by a generic type variable. Classes can be parametric over a reference type or one of the ground types (such as int, bool or float). We now see how we would re-implement the simple generic cells from our Java example in Objective Caml. (* File: programs/caml/Cell.ml *) class [’a] cell (value_init : ’a) = object val mutable value = value_init method get = value method set (new_value) = value <- new_value end ;; This class definition is parameterised by a type variable ’a, and by the parameter to the con- structor of the class. Caml does not support overloading so a class has only a single constructor, unlike Java. The cell class is used in the Ocaml top-level loop thus. # let c = new cell(3);; (* create a new cell *) val c : int cell = <obj> UG4 Advances in Programming Languages — 2005/2006 5 # c#get ;; (* invoke the get method *) - : int = 3 # c#set(4) ;; (* invoke the set method *) - : unit = () # c#get;; (* invoke the get method again *) - : int = 4 Subclassing and specialisation If we found that we used cells of strings almost exclusively in our application it might be worthwhile to subclass the cell class and specialise it to a cell of strings. This can be done in a very similar fashion in Ocaml and Generic Java. (* File: programs/caml/StringCell.ml *) class stringCell (s : string) = object inherit [string] cell s end ;; /* File: programs/java/StringCell.java */ class StringCell extends Cell<String> { StringCell(String s) { super(s); } } Bounded polymorphic methods So far, we have used Java’s generic methods to define methods which are parameterised on a generic class variable. We know that in Java’s object polymorphism we can define methods which are parameterised on a specific class (and all of its subclasses). We can combine these to define methods where the generic class parameter is bounded above by a specific superclass. For example, class C<A extends B> defines a generic class C whose parameter (A) is a subclass of B. As an example we will define a class of sorted lists, whose elements must be comparable. Before we progress to defining such a class we first implement a non-generic version, discover a problem with it, and then progress to defining a generic version. The non-generic version is called OrderedList and the generic version is called SortedList. UG4 Advances in Programming Languages — 2005/2006 6 /* File: programs/java/OrderedList.java */ /* A non-generic version */ public class OrderedList { /* Fields to hold the head of the list and the tail */ public Comparable head; public OrderedList tail; /* A constructor for sorted lists */ public OrderedList(Comparable head, OrderedList tail){ this.head = head; this.tail = tail; } /* Insert a new element, maintaining ordering */ public void insert (Comparable e) { OrderedList l = this; while(l.tail != null && l.head.compareTo(e) < 0) { l = l.tail; }; if (l.head.compareTo(e) >= 0) { l.tail = new OrderedList(l.head, l.tail); l.head = e; } else { l.tail = new OrderedList(e, l.tail); } } } The non-generic version of this class has the problem that ordered lists are inherently hetero- geneous, as OO collections typically are.
Recommended publications
  • G22.2110-003 Programming Languages - Fall 2012 Week 14 - Part 1
    G22.2110-003 Programming Languages - Fall 2012 Week 14 - Part 1 Thomas Wies New York University Review Last lecture I Exceptions Outline Today: I Generic Programming Sources for today's lecture: I PLP, ch. 8.4 I Programming in Scala, ch. 19, 20.6 Generic programming Subroutines provide a way to abstract over values. Generic programming lets us abstract over types. Examples: I A sorting algorithm has the same structure, regardless of the types being sorted I Stack primitives have the same semantics, regardless of the objects stored on the stack. One common use: I algorithms on containers: updating, iteration, search Language models: I C: macros (textual substitution) or unsafe casts I Ada: generic units and instantiations I C++, Java, C#, Scala: generics (also called templates) I ML: parametric polymorphism, functors Parameterizing software components Construct Parameter(s): array bounds, element type subprogram values (arguments) Ada generic package values, types, packages Ada generic subprogram values, types C++ class template values, types C++ function template values, types Java generic classes Scala generic types (and implicit values) ML function values (including other functions) ML type constructor types ML functor values, types, structures Templates in C++ template <typename T> class Array { public : explicit Array (size_t); // constructor T& operator[] (size_t); // subscript operator ... // other operations private : ... // a size and a pointer to an array }; Array<int> V1(100); // instantiation Array<int> V2; // use default constructor
    [Show full text]
  • Advanced-Java.Pdf
    Advanced java i Advanced java Advanced java ii Contents 1 How to create and destroy objects 1 1.1 Introduction......................................................1 1.2 Instance Construction.................................................1 1.2.1 Implicit (Generated) Constructor.......................................1 1.2.2 Constructors without Arguments.......................................1 1.2.3 Constructors with Arguments........................................2 1.2.4 Initialization Blocks.............................................2 1.2.5 Construction guarantee............................................3 1.2.6 Visibility...................................................4 1.2.7 Garbage collection..............................................4 1.2.8 Finalizers...................................................5 1.3 Static initialization..................................................5 1.4 Construction Patterns.................................................5 1.4.1 Singleton...................................................6 1.4.2 Utility/Helper Class.............................................7 1.4.3 Factory....................................................7 1.4.4 Dependency Injection............................................8 1.5 Download the Source Code..............................................9 1.6 What’s next......................................................9 2 Using methods common to all objects 10 2.1 Introduction...................................................... 10 2.2 Methods equals and hashCode...........................................
    [Show full text]
  • Java Generics Adoption: How New Features Are Introduced, Championed, Or Ignored
    Java Generics Adoption: How New Features are Introduced, Championed, or Ignored Chris Parnin Christian Bird Emerson Murphy-Hill College of Computing Microsoft Research Dept. of Computer Science Georgia Institute of Redmond, Washington North Carolina State Technology [email protected] University Atlanta, Georgia Raleigh, North Carolina [email protected] [email protected] Far too often, greatly heralded claims and visions of new language features fail to hold or persist in practice. Discus- ABSTRACT sions of the costs and benefits of language features can easily devolve into a religious war with both sides armed with little Support for generic programming was added to the Java more than anecdotes [13]. Empirical evidence about the language in 2004, representing perhaps the most significant adoption and use of past language features should inform change to one of the most widely used programming lan- and encourage a more rational discussion when designing guages today. Researchers and language designers antici- language features and considering how they should be de- pated this addition would relieve many long-standing prob- ployed. Collecting this evidence is not just sensible but a lems plaguing developers, but surprisingly, no one has yet responsibility of our community. measured whether generics actually provide such relief. In In this paper, we examine the adoption and use of generics, this paper, we report on the first empirical investigation into which were introduced into the Java language in 2004. When how Java generics have been integrated into open source Sun introduced generics, they claimed that the language software by automatically mining the history of 20 popular feature was \a long-awaited enhancement to the type system" open source Java programs, traversing more than 500 million that \eliminates the drudgery of casting." Sun recommended lines of code in the process.
    [Show full text]
  • Addressing Common Crosscutting Problems with Arcum∗
    Addressing Common Crosscutting Problems with Arcum∗ Macneil Shonle William G. Griswold Sorin Lerner Computer Science & Engineering, UC San Diego La Jolla, CA 92093-0404 {mshonle, wgg, lerner}@cs.ucsd.edu ABSTRACT 1. INTRODUCTION Crosscutting is an inherent part of software development and can Arcum is a framework for declaring and performing user-defined typically be managed through modularization: A module’s stable program checks and transformations, with the goal of increasing properties are defined in an interface while its likely-to-change automated refactoring opportunities for the user [21]. By using Ar- properties are encapsulated within the module [19]. The cross- cum, a programmer can view the implementation of a crosscutting cutting of the stable properties, such as class and method names, design idiom as a form of module. Arcum uses a declarative lan- can be mitigated with automated refactoring tools that allow, for guage to describe the idiom’s implementation, where descriptions example, the interface’s elements to be renamed [9, 18]. However, are composed of Arcum interface and Arcum option constructs. An often the crosscutting from design idioms (such as design patterns option describes one possible implementation of a crosscutting de- and coding styles) are so specific to the program’s domain that sign idiom, and a set of options are related to each other when they their crosscutting would not likely have been anticipated by the all implement the same Arcum interface. developers of an automated refactoring system. Arcum’s declarative language uses a Java-like syntax for first- The Arcum plug-in for Eclipse enables programmers to describe order logic predicate statements, including a special pattern nota- the implementation of a crosscutting design idiom as a set of syn- tion for expressing Java code.
    [Show full text]
  • REVERSE GENERICS Parametrization After the Fact
    REVERSE GENERICS Parametrization after the Fact Alexandre Bergel PLEIAD Laboratory, Computer Science Department (DCC), University of Chile, Santiago, Chile Lorenzo Bettini Dipartimento di Informatica, Universit`adi Torino, Italy Keywords: Generic programming, Java generics, C++ templates. Abstract: By abstracting over types, generic programming enables one to write code that is independent from specific data type implementation. This style is supported by most mainstream languages, including C++ with tem- plates and Java with generics. If some code is not designed in a generic way from the start, a major effort is required to convert this code to use generic types. This conversion is manually realized which is known to be tedious and error-prone. We propose Reverse Generics, a general linguistic mechanism to define a generic class from a non-generic class. For a given set of types, a generic is formed by unbinding static dependencies contained in these types. This generalization and generic type instantiation may be done incrementally. This paper studies the possible application of this linguistic mechanism to C++ and Java and, in particular, it reviews limitations of Java generics against our proposal. 1 INTRODUCTION more than 100 down-casts and up-casts and 70 uses of instanceof. This examination reveals that in many The concept of generic programming (Dos Reis and places the amount of up-casting subsequent down- J¨arvi, 2005), which has characterized functional pro- casting that is used almost makes the programs be- gramming for several decades, appeared in main- have like dynamically typed code. stream programming object-oriented languages such Note, that the need to make existing code generic as C++, only in the late 80s, where it motivated from may arise also in languages where generic types were the beginning the design of the Standard Template Li- already available.
    [Show full text]
  • C DEFINES and C++ TEMPLATES Professor Ken Birman
    Professor Ken Birman C DEFINES AND C++ TEMPLATES CS4414 Lecture 10 CORNELL CS4414 - FALL 2020. 1 COMPILE TIME “COMPUTING” In lecture 9 we learned about const, constexpr and saw that C++ really depends heavily on these Ken’s solution to homework 2 runs about 10% faster with extensive use of these annotations Constexpr underlies the “auto” keyword and can sometimes eliminate entire functions by precomputing their results at compile time. Parallel C++ code would look ugly without normal code structuring. Const and constexpr allow the compiler to see “beyond” that and recognize parallelizable code paths. CORNELL CS4414 - FALL 2020. 2 … BUT HOW FAR CAN WE TAKE THIS IDEA? Today we will look at the concept of programming the compiler using the templating layer of C++ We will see that it is a powerful tool! There are also programmable aspects of Linux, and of the modern hardware we use. By controlling the whole system, we gain speed and predictability while writing elegant, clean code. CORNELL CS4414 - FALL 2020. 3 IDEA MAP FOR TODAY History of generics: #define in C Templates are easy to create, if you stick to basics The big benefit compared to Java is that a template We have seen a number of parameterized is a compile-time construct, whereas in Java a generic types in C++, like std::vector and std::map is a run-time construct. The template language is Turing-complete, but computes These are examples of “templates”. only on types, not data from the program (even when They are like generics in Java constants are provided).
    [Show full text]
  • Java (Software Platform) from Wikipedia, the Free Encyclopedia Not to Be Confused with Javascript
    Java (software platform) From Wikipedia, the free encyclopedia Not to be confused with JavaScript. This article may require copy editing for grammar, style, cohesion, tone , or spelling. You can assist by editing it. (February 2016) Java (software platform) Dukesource125.gif The Java technology logo Original author(s) James Gosling, Sun Microsystems Developer(s) Oracle Corporation Initial release 23 January 1996; 20 years ago[1][2] Stable release 8 Update 73 (1.8.0_73) (February 5, 2016; 34 days ago) [±][3] Preview release 9 Build b90 (November 2, 2015; 4 months ago) [±][4] Written in Java, C++[5] Operating system Windows, Solaris, Linux, OS X[6] Platform Cross-platform Available in 30+ languages List of languages [show] Type Software platform License Freeware, mostly open-source,[8] with a few proprietary[9] compo nents[10] Website www.java.com Java is a set of computer software and specifications developed by Sun Microsyst ems, later acquired by Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment . Java is used in a wide variety of computing platforms from embedded devices an d mobile phones to enterprise servers and supercomputers. While less common, Jav a applets run in secure, sandboxed environments to provide many features of nati ve applications and can be embedded in HTML pages. Writing in the Java programming language is the primary way to produce code that will be deployed as byte code in a Java Virtual Machine (JVM); byte code compil ers are also available for other languages, including Ada, JavaScript, Python, a nd Ruby.
    [Show full text]
  • Programming-In-Scala.Pdf
    Cover · Overview · Contents · Discuss · Suggest · Glossary · Index Programming in Scala Cover · Overview · Contents · Discuss · Suggest · Glossary · Index Programming in Scala Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS MOUNTAIN VIEW,CALIFORNIA Cover · Overview · Contents · Discuss · Suggest · Glossary · Index iv Programming in Scala First Edition, Version 6 Martin Odersky is the creator of the Scala language and a professor at EPFL in Lausanne, Switzerland. Lex Spoon worked on Scala for two years as a post-doc with Martin Odersky. Bill Venners is president of Artima, Inc. Artima Press is an imprint of Artima, Inc. P.O. Box 390122, Mountain View, California 94039 Copyright © 2007, 2008 Martin Odersky, Lex Spoon, and Bill Venners. All rights reserved. First edition published as PrePrint™ eBook 2007 First edition published 2008 Produced in the United States of America 12 11 10 09 08 5 6 7 8 9 ISBN-10: 0-9815316-1-X ISBN-13: 978-0-9815316-1-8 No part of this publication may be reproduced, modified, distributed, stored in a retrieval system, republished, displayed, or performed, for commercial or noncommercial purposes or for compensation of any kind without prior written permission from Artima, Inc. All information and materials in this book are provided "as is" and without warranty of any kind. The term “Artima” and the Artima logo are trademarks or registered trademarks of Artima, Inc. All other company and/or product names may be trademarks or registered trademarks of their owners. Cover · Overview · Contents · Discuss · Suggest · Glossary · Index to Nastaran - M.O. to Fay - L.S. to Siew - B.V.
    [Show full text]
  • Harmonizing Classes, Functions, Tuples, and Type Parameters in Virgil III
    Harmonizing Classes, Functions, Tuples, and Type Parameters in Virgil III Ben L. Titzer Google [email protected] Abstract guages like Java first offered object-oriented emulation of func- Languages are becoming increasingly multi-paradigm. Subtype tions in the form of single-method interfaces like Runnable and polymorphism in statically-typed object-oriented languages is be- Comparator. Generics gave rise to even more complex emula- ing supplemented with parametric polymorphism in the form of tions of functions such as java.util.concurrent’s Callable generics. Features like first-class functions and lambdas are ap- and Guava’s Function [13] and Predicate. Now Java has pro- pearing everywhere. Yet existing languages like Java, C#, C++, posals for syntax for function types and closures in JSR 335 [17]. D, and Scala seem to accrete ever more complexity when they Similar developments occurred in both C++ and C#, with libraries reach beyond their original paradigm into another; inevitably older first evolving functional patterns before languages added syntactic features have some rough edges that lead to nonuniformity and pit- support. C# first allowed delegates, which are closures bound to a falls. Given a fresh start, a new language designer is faced with a method of an object, and then full lambdas. Scala set out to blend daunting array of potential features. Where to start? What is impor- object-oriented and functional styles while still primarily targeting tant to get right first, and what can be added later? What features the JVM. Not to be outdone, C++11 has added support for lambdas must work together, and what features are orthogonal? We report and a host of other new features.
    [Show full text]
  • Orthogonal Persistence in Java Supported by Aspect- Oriented Programming and Reflection
    CORE Metadata, citation and similar papers at core.ac.uk Provided by Repositório Científico do Instituto Politécnico do Porto Orthogonal Persistence in Java supported by Aspect- Oriented Programming and Reflection Rui Humbero R. Pereira J.Baltasar García Perez-Schofield Instituto Superior Contabilidade e Administração do Porto Departamento de Informática ISCAP/IPP Universidad de Vigo Porto, Portugal Vigo, España [email protected] [email protected] Abstract — The persistence concern implemented as an aspect the database. It was designed to be totally reusable without the has been studied since the appearance of the Aspect-Oriented need of any kind of adaption on the code. The following code paradigm. Frequently, persistence is given as an example that fragment shows the way an application can interact with data can be aspectized, but until today no real world solution has objects. applied that paradigm. Such solution should be able to enhance the programmer productivity and make the application less CPersistentRoot psRoot; prone to errors. To test the viability of that concept, in a previous Student student; study we developed a prototype that implements Orthogonal Student student2; Persistence as an aspect. This first version of the prototype was Course course; already fully functional with all Java types including arrays. In this work the results of our new research to overcome some // get a persistent root (psRoot) limitations that we have identified on the data type abstraction psRoot=new CPersistentRoot(); and transparency in the prototype are presented. One of our goals was to avoid the Java standard idiom for genericity, based //Get one Student object from the psRoot (the on casts, type tests and subtyping.
    [Show full text]
  • Java Generics: an Order-Theoretic Approach (Detailed Outline)
    Java Generics: An Order-Theoretic Approach Moez A. AbdelGawad Informatics Research Institute, SRTA-City, Alexandria, Egypt [email protected] Abstract Introduction The addition of generic classes, generic interfaces and parameterized types (i.e., in- 1 Generics have been added to Java so as to increase the stantiations of generic classes ) to Java has signifi- expressiveness of its type system. Generics in Java, cantly enhanced the expressiveness of its type sys- however, include some features—such as Java wild- tem [22, 23, 16, 19, 34, 26]. Support for generics cards, F -bounded generics, and Java erasure—that in Java and other mainstream nominally-typed OOP have been hard to analyze and reason about so far, languages similar to it—such as C# [1], Scala [28], reflecting the fact that the mathematical modeling of C++ [2], and Kotlin [3]—has several drawbacks how- generics in Java and other similar nominally-typed ever. object-oriented programming (OOP) languages is a For example, the bounded existentials model of challenge. As a result, the type systems of main- Java wildcards, while accurate, is exceedingly com- stream nominally-typed OOP languages, which are plex [36, 35, 18, 17, 32, 33]. The notion of “capture built based on current models of generics, are overly conversion,” which is based on the bounded existen- complex, which hinders the progress of these type tials model of wildcards, renders the generic type sys- systems. tem of Java fully comprehensible only to the most 2 In this paper we present a detailed outline of a advanced of Java developers . new approach to modeling Java generics that uses Further, support of some features in Java gener- concepts and tools from order theory, and we report ics has a number of irregularities or “rough edges.” on our progress in developing this approach.
    [Show full text]
  • Inheritance, Generics and Binary Methods in Java Herencia, Genéricos Y Métodos Binarios En Java
    Computación y Sistemas. Vol. 7 No. 2 pp. 113 - 122 © 2003, CIC-IPN, ISSN 1405-5546 Impreso en México Inheritance, Generics and Binary Methods in Java Herencia, Genéricos y Métodos Binarios en Java María Lucía Barrón-Estrada (1) and Ryan Stansifer (2) (1) Departamento de Sistemas y Computación Instituto Tecnológico de Culiacán Culiacán, Sin. CP 80220 México (2) Computer Science Department Florida Institute of Technology University Blvd.. Melbourne, FL 32901 [email protected], [email protected] Abstract Java has adopted a mechanism to support parameterized types that will be available in the next major release. A draft specification to add generics to the JavaTM Programming Language was published two years ago [1] and a new version of it in June 23, 2003 [2]. An extension of the type system based on F-bounded quantification is proposed. A binary method is a method that has one or more parameters of the same type as the object that receives the message. F-Bounded polymorphism and binary methods can’t be combined smoothly in object-oriented languages with nominal subtyping and single dispatch [3]. In this paper, we address some problems that can arise when binary methods are needed in parameterized classes and interfaces in the implementation of a Java program. Keywords: Binary methods, Inheritance, Java, Parameterized types. Resumen El lenguaje de programación Java ha adoptado un mecanismo para definir tipos parametrizados, el cual estará disponible para los usuarios en la próxima versión de su compilador. La primera especificación formal para incluir genéricos en Java fue publicada hace dos años y una nueva versión el pasado mes de Junio del 2003.
    [Show full text]