7 research outputs found

    A reflective implementation of Java multi-methods

    Full text link

    Attaining multiple dispatch in widespread object-oriented languages

    Get PDF
    Multiple dispatch allows determining the actual method to be executed, depending on the dynamic types of its arguments. Although some programming languages provide multiple dispatch, most widespread object-oriented languages lack this feature. Therefore, different implementation techniques are commonly used to obtain multiple dispatch in these languages. We evaluate the existing approaches, presenting a new one based on hybrid dynamic and static typing. A qualitative evaluation is presented, considering factors such as software maintainability and readability, code size, parameter generalization, and compile-time type checking. We also perform a quantitative assessment of runtime performance and memory consumption

    Multiple dispatch in Java using annotation processing

    Get PDF
    Dispatch is a mechanism in object-oriented programming languages used for distinguishing between methods with the same name and number of parameters. It works by examining the runtime types of parameters passed to a method call and selecting the most suitable method for them. Single dispatch selects a method based on the runtime type of just one of the parameters (the receiver), while the types of the rest of them are determined during compilation. Multiple dispatch determines the types of all the parameters during program execution, which is slower but more flexible. Java along with many other object-oriented languages supports single dispatch but not multiple dispatch. In such languages multiple dispatch can be simulated in different ways. The goal of this thesis was to create a library that uses annotations added to an ordinary Java program in order to generate code for simulating multiple dispatch. Because the dispatch logic is generated during compilation, it can be very complex without complicating the source code. The only change when writing a program that uses our library are additional annotations, which is much simpler than existing similar solutions that use special compilers or change the way methods can be used. There are three different versions of the library with three different mechanisms for simulating multiple dispatch: a decision tree with direct type inspection, a mechanism that uses reflection and an extended version of the visitor design pattern. The first two are similar to mechanisms used in other solutions while the third one is less known and is not found in the existing literature. In this thesis we show implementations of the three versions of our library and present the results of the experiments, where we compare them based on execution time, compilation time and size of the generated code

    Multiple dispatch in Java using annotation processing

    Get PDF
    Dispatch is a mechanism in object-oriented programming languages used for distinguishing between methods with the same name and number of parameters. It works by examining the runtime types of parameters passed to a method call and selecting the most suitable method for them. Single dispatch selects a method based on the runtime type of just one of the parameters (the receiver), while the types of the rest of them are determined during compilation. Multiple dispatch determines the types of all the parameters during program execution, which is slower but more flexible. Java along with many other object-oriented languages supports single dispatch but not multiple dispatch. In such languages multiple dispatch can be simulated in different ways. The goal of this thesis was to create a library that uses annotations added to an ordinary Java program in order to generate code for simulating multiple dispatch. Because the dispatch logic is generated during compilation, it can be very complex without complicating the source code. The only change when writing a program that uses our library are additional annotations, which is much simpler than existing similar solutions that use special compilers or change the way methods can be used. There are three different versions of the library with three different mechanisms for simulating multiple dispatch: a decision tree with direct type inspection, a mechanism that uses reflection and an extended version of the visitor design pattern. The first two are similar to mechanisms used in other solutions while the third one is less known and is not found in the existing literature. In this thesis we show implementations of the three versions of our library and present the results of the experiments, where we compare them based on execution time, compilation time and size of the generated code

    MultiJava: Design Rationale, Compiler Implementation, and Applications

    Get PDF
    MultiJava is a conservative extension of the Java programming language that adds symmetric multiple dispatch and open classes. Among other benefits, multiple dispatch provides a solution to the binary method problem. Open classes provide a solution to the extensibility problem of object-oriented programming languages, allowing the modular addition of both new types and new operations to an existing type hierarchy. This paper illustrates and motivates the design of MultiJava and describes its modular static typechecking and modular compilation strategies. Although MultiJava extends Java, the key ideas of the language design are applicable to other object-oriented languages, such as C# and C++, and even, with some modifications, to functional languages such as ML. This paper also discusses the variety of application domains in which MultiJava has been successfully used by others, including pervasive computing, graphical user interfaces, and compilers. MultiJava allows users to express desired programming idioms in a way that is declarative and supports static typechecking, in contrast to the tedious and type-unsafe workarounds required in Java. MultiJava also provides opportunities for new kinds of extensibility that are not easily available in Java

    Java Multi-Method Framework

    Get PDF
    International audienc
    corecore