Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #14040

generics

Date 2012-04-30 00:13 +0100
From Neil Morris <neil.morris4@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject generics
Message-ID <Ha6dnQN32-O6VgDSnZ2dnUVZ8q-dnZ2d@brightview.co.uk> (permalink)

Show all headers | View raw


Dear newsgroup

With the following code, what is the difference from one written with 
Bounded Type Parameters? the code has type 'Number' with the 'add' 
method using the 'Integer' type. How can I stop a subtype from being 
passed to the 'add' method?

public class Test<T> {
  private T t;
  public void add(T t) {
  this.t = t;
  }
  public T get() {
  return t;
  }
  public static void main(String[] args) {
  Test<Number> test = new Test<Number>();
  test.add(new Integer(10));
  System.out.println(test.get());
  }
}


thanks in advance

Neil

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

generics Neil Morris <neil.morris4@googlemail.com> - 2012-04-30 00:13 +0100
  Re: generics Arne Vajhøj <arne@vajhoej.dk> - 2012-04-29 19:39 -0400
    Re: generics Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-04-29 16:48 -0700
  Re: generics markspace <-@.> - 2012-04-29 17:48 -0700

csiph-web