public class A public class B: Inner Dietetic dictionary (integer, A) Dim Dictib New DictA = DictB
The dictionary does not work, because the type can not be changed. Is it possible anyway?
No, you are participating in the problem of generic variance, except for certain special methods .NET Not supported in
The reason for this is: After your last line, you have a dictionary with two "thoughts" on it, effectively imagine now that you have written:
< Code> DictA.Add (1, new A ())
(Sorry if my VB is a bit far away.) "Non-B" in the dictionary, but Dictub thinks that All values will be B Examples.
One of the main purposes of generic is to capture potential types of failures at compile time instead of execution time - meaning that this code should fail to compile, which is actually the lack of variance The reason is fine.
When you are used for general heritage, it is a bit comfortable, but it makes sense. A bunch of banana is not just a collection of fruits - it's a collection of kayla .
By using wild protection on behalf of the Java caller, it takes a slightly different stance - this will be you looking at the "add" of the dictionary for the digit, for example, as you do in Dtb Whatever you add, it will be fine in DictA. Java's generics are very different for generic NAT ...
Comments
Post a Comment