ePrints.FRI - University of Ljubljana, Faculty of Computer and Information Science

Multiple dispatch in Java using annotation processing

Nejc Kišek (2018) Multiple dispatch in Java using annotation processing. MSc thesis.

[img]
Preview
PDF
Download (1542Kb)

    Abstract

    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.

    Item Type: Thesis (MSc thesis)
    Keywords: dispatch, multiple dispatch, annotations, annotation processing, generating code, Java, javac
    Number of Pages: 60
    Language of Content: Slovenian
    Mentor / Comentors:
    Name and SurnameIDFunction
    doc. dr. Jurij Mihelič305Mentor
    Link to COBISS: http://www.cobiss.si/scripts/cobiss?command=search&base=51012&select=(ID=1538035139)
    Institution: University of Ljubljana
    Department: Faculty of Computer and Information Science
    Item ID: 4305
    Date Deposited: 05 Nov 2018 15:08
    Last Modified: 19 Nov 2018 13:00
    URI: http://eprints.fri.uni-lj.si/id/eprint/4305

    Actions (login required)

    View Item