Re: generics

Discussion in 'Java' started by Stefan Ram, Apr 30, 2012.

  1. Stefan Ram

    Stefan Ram Guest

    Neil Morris <> writes:
    >How can I stop a subtype from being passed to the 'add'
    >method?


    When a method has a parameter of type T, then an
    expression of type U is acceptable as the corresponding
    argument expression, whenever U is a subtype of T.

    This cannot be changed.

    To accept only expressions of type T as argument
    expressions, T must be final.

    To accept only objects of type T as argument values,
    the parameter value must be checked using ».getClass«.
    Stefan Ram, Apr 30, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Willem Oosthuizen
    Replies:
    1
    Views:
    2,771
    Jonathan Bromley
    Jul 9, 2003
  2. Acciduzzu

    Integers only as generics?

    Acciduzzu, Sep 22, 2003, in forum: VHDL
    Replies:
    4
    Views:
    704
    Allan Herriman
    Sep 23, 2003
  3. valentin tihomirov

    generics in TB

    valentin tihomirov, Dec 17, 2003, in forum: VHDL
    Replies:
    4
    Views:
    571
    valentin tihomirov
    Dec 18, 2003
  4. Juergen Berchtel
    Replies:
    1
    Views:
    5,966
    John C. Bollinger
    May 20, 2005
  5. Soul
    Replies:
    0
    Views:
    502
Loading...

Share This Page