c# - Is Generic Types in C # like in Java? -
this question has answer here:
- c# vs java generics [duplicate] 4 answers
i studied java long time , acquainted operation of generic types in language : know there @ compile time , suffering type erasure @ end of ( @ runtime information not available ) , have notion of difficulties when applying polymorphism on generic types .
now learning c # , , noticed although language use similar notation ( type ) semantics not seem same . example , see question did c # runtime stores information of generic types instead of discarding , unlike java, correct? also, have never seen example in c # utilizes " jokers " ( wildcards ) , type < ? extends tipogenerico > . possible ( or necessary ) in language ?
finally , c # supports individual methods ( not classes ) generics ? if yes , equivalent syntax of construction in java :
public <t> void method (t parameter1 , parameter2 <t> list ) {
if there additional details deserves emphasis , or maybe reference material learn more , welcome.
for example , see question did c # runtime stores information of generic types instead of discarding , unlike java, correct?
yes, correct. c# doesn't suffer limitations of type erasure in way.
also, have never seen example in c # utilizes " jokers " ( wildcards ) , type < ? extends tipogenerico > . possible ( or necessary ) in language ?
yes, done via generic constraints, example:
public class sometype<t> t : iequatable<t> {
this create class type t
must implement iequatable<t>
.
finally , c # supports individual methods ( not classes ) generics ? if yes , equivalent syntax of construction in java :
public void method<t>(t parameter1, list<t> parameter2) {
Comments
Post a Comment