Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:16:38+00:00 2026-06-15T13:16:38+00:00

In Visual Basic, I want to create an interface that includes a function that

  • 0

In Visual Basic, I want to create an interface that includes a function that returns an object of the implementing class. That is

public interface I
  function maker as ???
end interface

public class X
  implements I
  function maker as X
    return new X()
  end function
end class

public class Y
  implements I
  function maker as Y
    return new Y()
  end function
end class

Is there a way to say that? I suppose I could always say that maker returns an I rather than an X or a Y, but then callers would have to cast it. I thought of defining the interface as

public interface I(of ii as I)

But the whole point in doing this was so I could create a generic class that uses an of I, and if I say that, then the compiler insists on an infinite regression of I(of I(of I...

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:16:39+00:00Added an answer on June 15, 2026 at 1:16 pm

    Not exactly, but you can do this:

    Public Interface I(Of T)
        Function Maker() As T
    End Interface
    
    Public Class X
        Implements I(Of X)
    
        Public Function Maker() As X Implements I.Maker
            Return New X()
        End Function
    End Class
    

    Or, like this:

    Public Interface I
        Function Maker() As I
    End Interface
    
    Public Class X
        Implements I
    
        Public Function Maker() As I
            Return New X()
        End Function
    End Class
    

    Neither of these options force the derived class to return an instance of their own type, but they allow you to implement it that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom form (in visual basic .NET) that will stop
I want to create a monopoly board and the ludo game in Visual Basic.NET
I want a code that when applied to text in Visual Basic 2008 it
I'm using Visual Basic 9 (VS2008) I want to create new Tabs as and
I want to create a List in an ActiveX component project in Visual Basic
I'm trying to create a simple visual basic 6 program/database that uses ms access
how do I create a geometric shape as a class? Visual basic has a
I'm trying to create an app in Visual Basic that will allow a user
We have a front end written in Visual Basic 6.0 that calls several back
Language Visual Basic 6. I want to know if there is an open source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.