Java interview

From Hawk Wiki
Revision as of 03:16, 4 April 2012 by Hall (Talk | contribs) (Created page with "==Basic== ===Generic === Similar with c++ template. <pre class="java"> * * Generic version of the Box class. * @param <T> the type of value being boxed: public class Box<...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Basic

Generic

Similar with c++ template.

/**
 * Generic version of the Box class.
 * @param <T> the type of value being boxed
 */

public class Box<T> {

    // T stands for "Type"
    private T t;

    public void add(T t) {
        this.t = t;
    }

    public T get() {
        return t;
    }
}