`
ymanyang
  • 浏览: 4816 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
社区版块
存档分类
最新评论

Java Generic Types

    博客分类:
  • Java
 
阅读更多

generic type is a generic class or interface that is parameterized over types. It can be used to generalize the type of parameters and return value in coding without the risk to pass a wrong type to its methods. Like the following example:

/**
 * Generic version of the Box class.
 * @param <T> the type of the value being boxed
 */
public class Box<T> {
    // T stands for "Type"
    private T t;

    public void set(T t) { this.t = t; }
    public T get() { return t; }
}
 When initiate this class or use it, it only need to replace the type parameter with desired class type.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics