Generics in Java - Generic Class Definitions

Generic Class Definitions

Here is an example of a generic class:

public class Entry { private final K key; private final V value; public Entry(K k,V v) { key = k; value = v; } public K getKey { return key; } public V getValue { return value; } public String toString { return "(" + key + ", " + value + ")"; } }

Note that the above class is for illustration of Java generics only.

This generic class can be used in the following way:

Entry grade440 = new Entry("mike", "A"); Entry marks440 = new Entry("mike", 100); System.out.println("grade: " + grade440); System.out.println("marks: " + marks440);

Read more about this topic:  Generics In Java

Famous quotes containing the words generic, class and/or definitions:

    “Mother” has always been a generic term synonymous with love, devotion, and sacrifice. There’s always been something mystical and reverent about them. They’re the Walter Cronkites of the human race . . . infallible, virtuous, without flaws and conceived without original sin, with no room for ambivalence.
    Erma Bombeck (20th century)

    The intellectual is a middle-class product; if he is not born into the class he must soon insert himself into it, in order to exist. He is the fine nervous flower of the bourgeoisie.
    Louise Bogan (1897–1970)

    What I do not like about our definitions of genius is that there is in them nothing of the day of judgment, nothing of resounding through eternity and nothing of the footsteps of the Almighty.
    —G.C. (Georg Christoph)