Venkat Subramaniam · 2014
In Part-I and II we discussed the benefits and usage of Java Generics, and how it is implemented under the hood. In this Part-III, we conclude with discussions on issues with mixing generic and non-generic (raw-type) code, and the issues of converting a non-generic legacy code to generics. Mixing Generic and non-generic code Let’s consider the following example: import java.util.ArrayList;
Cited by 0
Muhammad Shoaib Farooq (526843), Sher Afzal Khan (526844), Farooq Ahmad (526845) et al. · Figshare · 2015
Cited by 0Open access
Barrón Estrada, María Lucía, Stansifer, Ryan · Redalyc (Universidad Autónoma del Estado de México) · 2003
"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-boundedquantification is proposed. A binary method is a method that has one or more parameters of the same type asthe object that receives the message. F-Bounded polymorphism and binary methods cant be combinedsmoothly 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 parameterizedclasses and interfaces in the implementation of a Java program."
Cited by 0
Krishnaprasadt Thirunarayan, Günter Kniesel, Haripriyan Hampapuram · 2000
This paper presents Java language from an object-oriented software construction perspective. It explainst he implicat ions of banning generics and mult iple inherit ance of classes, and explorest he pat t erns andt he idioms used byt he Java designers and programmerst o redeemt heir benefit s. The paper also discusses an alt ernat ivet o mult iple inherit ance, as incorporat ed in Lava, which extends Java with constructs for type-safe automatic forwarding.
Cited by 0
Richard Wiener · The Journal of Object Technology · 2004
Covariance: Competent Compilers Can Catch All Catcalls" by Mark Howard et al).Wildcards have been introduced into the generic lexicon of Java 1.5 to provide more flexibility in the absence of covariant typing.The declaration Collection<T> myCollection declares myCollection as a collection with some unknown element type.
Cited by 0Open access
David Ooms, Steven Stappaerts · 2004
Cited by 0
John Altidor, Yannis Smaragdakis · 2014
Wildcard annotations can improve the generality of Java generic libraries, but require heavy manual effort. We present an algorithm for refactoring and inferring more general type instantiations of Java generics using wildcards. Compared to past approaches, our work is practical and immediately applicable: we assume no changes to the Java type system, while taking into account all its intricacies. Our system allows users to select declarations (variables, method parameters, return types, etc.) to generalize and considers declarations not declared in available source code. It then performs an inter-procedural flow analysis and a method body analysis, in order to generalize type signatures. We evaluate our technique on six Java generic libraries. We find that 34% of available declarations of variant type signatures can be generalized - i.e., relaxed with more general wildcard types. On average, 146 other declarations need to be updated when a declaration is generalized, showing that this refactoring would be too tedious and error-prone to perform manually.
Cited by 6Open access
BOJCHEVSKI, KONSTANTIN · Repository of the University of Ljubljana (University of Ljubljana) · 2023
Generics are a powerful tool in object-oriented programming languages, especially in the Java programming language. They play an important role in software development, since they enable the programmer to write typeindependent code in a type-safe way. In a nutshell, a generic Java class (or method) is a class (or method) parameterized with an arbitrary number of types. When using a generic class or method, we specify concrete values for the type parameters, effectively tailoring the code of the class or method for concrete types. Another benefit of Java generics is that type safety is enforced during compilation rather than execution. The C++ programming language has a concept parallel to Java generics; these are templates. C++ templates and Java generics are similar to one another in terms of code syntax, the provided support for parameterizing types, and the most frequent use cases. However, they are actually implemented in a significantly different way, and there are important differences in their use and background semantics. In this thesis, we will show examples for both Java generics and C++ templates. We will discuss their similarities and differences, as well as advantages and disadvantages.
Cited by 0Open access
Mirko Viroli · Electronic Notes in Theoretical Computer Science · 2005
After several years from Sun Microsystems' call-for-proposals for adding generics to the Java Programming Language, JDK 1.5 will be finally shipped with a compile-time support for generics. However, differently e.g. from the current implementation of .NET Common Language Runtime, run-time support to generics — also commonly referred to as reification of type parameters — is not provided, leading to a number of well-known inadequacies which might potentially be critical. In this paper we present the EGO compiler (Exact Generics on Demand). This is the result of a project developed in collaboration with Sun Microsystems as an effort to provide run-time generics in a smooth way, without requiring any change on the JVM or on any other run-time support. The core solution is a sophisticated translation of code based on the type-passing style, where run-time type information is automatically created on a by-need basis, limiting as most as possible run-time overhead while retaining interoperability with legacy Java code. We present the main aspects of this development, from basic design to implementation and deployment issues. Many relevant aspects that typical raise when implementing advanced type systems over a mainstream programming language are discussed, shading light to some effective implementation techniques.
Cited by 7Open access
Neha Kumari, Rajeev Kumar · International Journal of Engineering Trends and Technology · 2023
Understanding a complex type structure and its use in a type-safe manner is a difficult task. The recursive generic type is a complex variant one can expect by finding the recursion. It has major significance in generic programming for solving binary method problems and mimicking self-type. However, improper use of recursive generics can cause vulnerabilities in source code. To avoid unsafe practices, a programmer must be aware of the recursive generic presence in source code. In Java generics, the type recursion can be found at a class or interface declaration. Therefore, it is appropriate to distinguish class type at declaration time itself. In this paper, we use a machine learning approach to find recursive and non-recursive generic types in Java source code. We collect data from ten contemporary Java projects and prepare a dataset with generic-specific attributes. The lesser presence of recursive generic type in Java projects causes an imbalanced dataset. Initially, the dataset results were highly imbalanced. Therefore, we resampled the dataset and used the dataset to train decision tree-based classifiers. Using standard performance metrics, we conduct a comparative analysis to find a (near-) optimal classifier among the six decision tree-based classifiers. Our analysis reasserts that the ensemble-based ``Random Forest Classifier
Cited by 0Open access
Raúl Marticorena Sánchez, Carlos López Nozal, Yania Crespo et al. · 2010
The addition of support for genericity to mainstream programming languages has a notable influence in refactoring tools. This also applies to the JAVA programming language. Those versions of the language specification prior to JAVA 5 did not include support for generics. Therefore, refactoring tools had to evolve to modify their refactoring implementations according to the new language characteristics in order to assure the correct effects when transforming code containing generic definitions or using generic instantiations. This paper presents an evaluation of the behaviour of refactoring tools on source code that defines or uses generics. We compare the behaviour of five refactoring tools on a well known refactoring, Extract Method, and its implementation for the JAVA language. We distill the lessons learned from our evaluation into requirements that have to be taken into account by refactoring tools in order to fully conform to this new language feature.
Cited by 3
Neha Kumari, Rajeev Kumar · ZooKeys · 2025
The two most significant yet complex elements of Java generics are wildcards and type argument inference. Both processes rely on the compiler. Even though type argument inference and wildcard execution are implicit processes, a programmer should be aware of them to make the most of the features. A compiler error message tells much about the code and the process mechanism. If the error message is unambiguous and sound, it is easy for the programmer to debug the code. However, in the context of wildcard-type argument inference, the current Javac compiler emits cryptic and imprecise error messages. A programmer may get confused about the inference outcome and failure, so it will be difficult to resolve the errors easily. In this paper, we propose a few additions to the current Wildcard-based type inference algorithm to get detailed and valuable error messages. We implement a Java compiler plugin tool based on the proposed algorithm. The plugin can be easily executed through the Java command line. It gives a comprehensive error message that aids programmers in resolving errors more effectively.
Cited by 0Open access
Peter Madsen, Niels T. Johansen · 2004
Sun Microsystems and Microsoft are preparing generics as part of the upcomming releases of Java 1.5 and C # 2.0.NET respectively. This paper is based on the currently available beta versions that support generics [versions note?]. We will outline some of the differences between generic Java and generic C # in relation
Cited by 0
FOO YONG QI · National University of Singapore · 2023
Master's
Cited by 0
Moez A. Abdelgawad · 2014
For helping themselves in writing, debugging and maintaining their software, professional OO software developers keep in their minds an im-age of the subtyping relation between types in their software while they are developing their software. In pre-generics Java [17], the structure of the subtyping mental image was simple: the graph of the subtyping re-lation between classes and interfaces (i.e., with multiple-inheritance of interfaces) was a directed-acyclic graph (or DAG), and the graph of the subtyping relation between classes alone (i.e., with single-inheritance only, more accurately called the ‘subclassing ’ relation) was simply a tree. Trees are well-known data structures, and a DAG, in short, is essentially a tree where a node is further allowed to have more than one parent node (i.e., not just one parent as in a tree) but the node cannot be a parent of itself, even if indirectly; a DAG can thus have no cycles, hence being ‘acyclic. ’ This fact about the graph of the subtyping relation applied not only to Java but, more generally, also to the non-generic sublanguage of nominally-typed OO languages similar to Java, such as C # [1], C++ [2], and Scala [21]. The goal of this casual essay is to present and defend, even if incom-pletely and not quite rigorously, a hunch and intuition the author had years ago about the graph of the subtyping relation in Java after gener-ics were added to it. The author observed that: after the addition of generics—and of wildcards in particular—to Java, the graph of the sub-typing relation is still a DAG, but no longer a simple DAG but rather one whose structure can be better understood as a fractal. Today, generics and wildcards (or some other form of ‘variance annotations’) are a standard feature of mainstream nominally-typed OO languages. Accordingly, the shape of the subtyping relation in nominally-typed OO languages is more complex than a tree or a simple DAG. Given the popularity of fractals, the fractals observation may help OO software developers keep a useful and intuitive mental image of their software’s subtyping relation, even if it is one a little more frightening, and amazing, than before. 1 ar
Cited by 0
Vaskaran Sarcar · Apress eBooks · 2019
Generic programming is an important concept in Java. It was introduced in JDK 5, and since then it has become an integral part of Java programming. The power of generic programming is enormous. It will make your program type-safe and flexible. Generics are often used with collections frameworks. So, once you are familiar with Java collections, you will be better able to use generics. This chapter provides a brief overview of generics.
Cited by 0
Péter Attila Soha, Norbert Pataki · Acta Cybernetica · 2022
Type parametrization is an essential construct in modern programming languages. On one hand, Java offers generics, on the other hand, C++ offers templates for highly reusable code. The mechanism between these constructs differs and affects usage and runtime performance, as well. Java uses type erasure, C++ deals with instantiations.In this paper, we argue for an approach in Java which is similar to C++ template construct. We evaluate the runtime performance of instantiated code and we present our tool which is able to use Java generics as templates. This tool generates Java source code. We present how this approach improves the usage of Java generics.
Cited by 0Open access
Chris Parnin, Christian Bird, Emerson Murphy-Hill · 2011
Support for generic programming was added to the Java language in 2004, representing perhaps the most significant change to one of the most widely used programming languages today. Researchers and language designers anticipated this addition would relieve many long-standing problems plaguing developers, but surprisingly, no one has yet measured whether generics actually provide such relief. In this paper, we report on the first empirical investigation into how Java generics have been integrated into open source software by automatically mining the history of 20 popular open source Java programs, traversing more than 500 million lines of code in the process. We evaluate five hypotheses, each based on assertions made by prior researchers, about how Java developers use generics. For example, our results suggest that generics do not significantly reduce the number of type casts and that generics are usually adopted by a single champion in a project, rather than all committers.
Cited by 49
Daniel Von Dincklage · 2008
Generics offer significant software engineering benefits since they provide code reuse without compromising type safety. Thus generics will be added to the Java language in the next release. While this extension to Java will help programmers when they are writing new code, it will not help legacy code unless it is rewritten to use generics. In our experience, manually modifying existing programs to use generics is complex and can be error prone and labor intensive. We describe a system, Ilwith, that (i) converts non-generic classes to generic classes and (ii) rewrites their clients to use the newly generified classes. Our experiments with a number of Java container classes show that our system is effective in modifying legacy code to use generics.
Cited by 0
Chris Parnin, Christian Bird, Emerson Murphy-hill et al. · 2012
Abstract Support for generic programming was added to the Java language in 2004, representing perhaps the most significant change to one of the most widely used programming languages today. Researchers and language designers anticipated this addition would relieve many long-standing problems plaguing developers, but surprisingly, no one has yet measured how generics have been adopted and used in practice. In this paper, we report on the first empirical investigation into how Java generics have been integrated into open source software by automatically mining the history of 40 popular open source Java programs, traversing more than 650 million lines of code in the process. We evaluate five hypotheses and research questions about how Java developers use generics. For example, our results suggest that generics sometimes reduce the number of type casts and that generics are usually adopted by a single champion in a project, rather than all committers. We also offer insights into why some features may be adopted sooner and others features may be held back.
Cited by 0