Category: Generics

Generics

Generic Classes in Java

Generic Classes in Java

Java Generics was introduced to deal with type-safe objects. It makes the code stable.Java Generics methods and classes, enables programmer with a single method declaration, a set of related methods, a set of related...

Vectors in Java

Vectors in Java

Vector implements a dynamic array. It is similar to ArrayList, but with two differences: Vector is synchronized. Vector contains many legacy methods that are not part of the collections framework. Vector proves to be...

Generic Interfaces

Generic Interfaces

you can also have generic interfaces. Generic interfaces are specified just like generic classes. Here is an example. It creates an interface called MinMax that declares the methods min( ) and max( ), which...

Bounded Types

Bounded Types

In the preceding examples, the type parameters could be replaced by any class type. This is fine for many purposes, but sometimes it is useful to limit the types that can be passed to...

Generic Classes

Generic Classes

as functions classes can also be generic which accepts data types of any type variables. The syntax to define a generic class as :

Generics Introduction

Generics Introduction

It would be nice if we could write a single sort method that could sort the elements in an Integer array, a String array or an array of any type that supports ordering (i.e.,...