Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: generics (http://www.velocityreviews.com/forums/t945840-re-generics.html)

Stefan Ram 04-29-2012 11:42 PM

Re: generics
 
Neil Morris <neil.morris4@googlemail.com> 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«.



All times are GMT. The time now is 03:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.