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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:25:18+00:00 2026-06-05T00:25:18+00:00

One thing that irritates me about Java is the awful implementation of compile-time translation

  • 0

One thing that irritates me about Java is the awful implementation of compile-time translation of generic type arguments.

I can observe and understand that the C# implementation is far better, but I’m confused as to how it works.

Essentially, how can you say:

T t = new T()

If you don’t know the type of T and therefore don’t know the constructor argument requirements?

I can see

Class<T> cl = T.class

or

T[] tarr = new T[0]

but I don’t see how you can really create a new instance of T if you don’t know the requirements of constructing it?

  • 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-05T00:25:19+00:00Added an answer on June 5, 2026 at 12:25 am

    You can only do new T(); if T is constrained to have a plain, parameterless public constructor, for instance:

    public class Foo<T> where T : new() {
        private myT = new T();
    }
    

    Additionally, there is no way to specify that any other sort of constructor exist. This is not possible:

    // Doesn't work
    public class Foo<T> where T : new(String, Int) {
        private myT = new T("Foo", 5);
    }
    

    To your other points, this is how you get the type of T at runtime:

    var tType = typeof(T);
    

    and creating an array of T doesn’t actually create any instances (unless T is a value type, in which case it creates the default value of that type):

    // Space for 32 T's, but nothing in the array.
    // If T is a value type, like an int for instance, 
    // each one would have the default value (0 for int, for example)
    var arrayOfT = new T[32];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing that bothers me about nHibernate is that it is not 100% compile
One thing that really bothers me about Google Code is that fact that it
Coming from a C++ background, one thing that confuses me about Objective C is
One thing that I like to do from time to time is do a
One thing that has bothered me about C# since its release was the lack
One thing that has driven me nuts about SharePoint2007 is the apparent inability to
One thing that I've always hated more than just about anything in MS SQL
There's one thing that I can't figure out. When I try to run rails
One thing that I hate about documentation at times (when you're a beginner) is
If there's one thing that I hate about SQL Server, it's the horribly unhelpful

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.