I got an object(myObject) type Object. myObject inherits of another class that contain a fonction (ImyFunction). I want to call the function, but my project need to be in “Option Strict On”. So it ask for declaration of the object.
Public MustInherit Class IClass(Of T1)
...
Public Sub IMyFunction()
...
Public Class myClass1 : Inherits IClass(Of Item1)
...
Public Class myClass2 : Inherits IClass(Of Item2)
dim obj as object = new myClass1
...
obj.IMyFunction 'at this moment, I dont know whish class base of IClass I have
(its just a sample)
I cant do obj.IMyFunction because of the strict option.
Maybe there’s a cast way?
The
MustInheritkeyword does not mean that you cannot use it as a variable type, it just means that you cannot instantiate it. For instance:However since, it’s generic, you have to specify the type of
T1, so there’s no way to do what I think it is that you really want to do:What I would recommend, in this case, would be to make either a non-generic base class or interface, like this:
Then, you could do something like this: