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 7810543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:49:16+00:00 2026-06-02T03:49:16+00:00

Can anybody post the Java version of this VB.NET code? Public Function FetchDoc(Of T

  • 0

Can anybody post the Java version of this VB.NET code?

    Public Function FetchDoc(Of T As {New, IRepoDocument})(ByVal docId As String) As IRepoDocument Implements IDocRepository.FetchDoc

        Dim repoDoc As New T

        //some code to init repoDoc

        Return repoDoc

    End Function

This function accepts and create a instance of any class implementing IRepoDocument and has a no-argument constructor.

The only way I found is:

public <T extends IRepoDocument> IRepoDocument FetchDoc(String idDoc, Class<T> clazz)
    throws InstantiationException, IllegalAccessException 
{
  return clazz.newInstance();
}

But I want to suppress Class<T> clazz as input parameter.

  • 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-02T03:49:19+00:00Added an answer on June 2, 2026 at 3:49 am

    You cannot create an instance in Java without a Class instance to specify what class the instance is of — except for anonymous classes (see below). You can get that class instance as a parameter, or hide it under a rock, or fish it out of the ocean, but you have to have it at runtime. The classes associated with the generics are removed by type erasure and just aren’t there.

    I don’t know VB.NET from stringbeans, but you might, in some cases, be looking for an anonymous class.

    new IRepoDocument() { ......fill in code };
    

    In this case, there’s be no <T> at all, the return type would just be IRepoDocument.

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

Sidebar

Related Questions

Can anybody help me make this work, the idea is , if a post,
Could anybody post here some code how can I read word by word from
Can anybody post a link to a comparison chart, or even to a duplicated
Can anybody help me understand why this update query isn't updating the fields in
Can anybody help me out with this exception. I have tried couple of fixes
can anybody help me with this ? I have added some custom fields to
Can anybody tell me why is the record not inserted? This is my one
everyone. I'm new here and this is my first post. I'm creating a simple
Hy there! I'm using this piece of code, to copy some files on post-build-event:
Can anybody help me how to invoke the post method provided here. I am

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.