vb.net - How does "Overloads" work in a child class? -


i have base class , child class , both have same property , don't understand why vb wants me use "overloads" property in child class. difference child class version of property shared while parent class there structure. properties this:

public mustinherit class parent     public readonly property species string                     return "should species child."          end     end property end class  public class child     inherits parent     public shared readonly property species string                     return "species1"         end     end property end class 

species flagged in line public shared readonly property species string in child class warning message

property 'species' shadows overloadable member declared in base class 'parent'. if want overload base method, method must declared 'overloads'.

what want know why want overloaded? overloading typically used when different parameters being passed functions same name documented, i've found nothing explaining why overloads suggested in situation this.

note: code reports "species1" regardless of if have "overloads" or not adding confusion of does...

if want overload base method, method must declared 'overloads'.

the error message generic. note how talks method though warning property. cannot overload property.

if king of france, have written error message like:

property 'species' hides 'species' property inherited 'parent' base class. use shadows keyword suppress warning if hiding intended. change name of property if hiding not intended.

this warning should never ignored because identifies code smell. using shared keyword child.species strange , not intended. code uses child object through reference of type parent wrong species name since use base property. more sane thing here declare parent.species property overridable , use overrides keyword in child.species property declaration, without shared.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -