当前位置:   article > 正文

Java Generic Types

unsupported class file major version 6382

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:

  1. /**
  2. * Generic version of the Box class.
  3. * @param <T> the type of the value being boxed
  4. */
  5. public class Box<T> {
  6. // T stands for "Type"
  7. private T t;
  8. public void set(T t) { this.t = t; }
  9. public T get() { return t; }
  10. }
 When initiate this class or use it, it only need to replace the type parameter with desired class type.
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/767685
推荐阅读
相关标签
  

闽ICP备14008679号