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)

    Much of the wisdom of the world is not wisdom, and the most illuminated class of men are no doubt superior to literary fame, and are not writers.
    Ralph Waldo Emerson (1803–1882)

    Lord Byron is an exceedingly interesting person, and as such is it not to be regretted that he is a slave to the vilest and most vulgar prejudices, and as mad as the winds?
    There have been many definitions of beauty in art. What is it? Beauty is what the untrained eyes consider abominable.
    Edmond De Goncourt (1822–1896)