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

  • Home
  • SEARCH
  • 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 8471381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:46:51+00:00 2026-06-10T16:46:51+00:00

Another very basic question regarding generics in Java and follows directly from a previous

  • 0

Another very basic question regarding generics in Java and follows directly from a previous question of mine . Aren’t we providing the same information to the compiler two times by writing the code below . Why do we need to provide the both in the left hand side as well as on the right hand side ?

List<Number> numbers = new ArrayList<Number>();

Edit: As I see in some answers that it it not required any more in java 7 onwards. But I would like to know what was the reason that it wasn’t possible before java 7 ?

  • 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-10T16:46:52+00:00Added an answer on June 10, 2026 at 4:46 pm

    Because pre java 7 does not support generic type inference for constructors. This is solved in java 7 by the diamond operator.

    You could also write generic factory methods as a workaround like:

     public static <T> List<T> createArrayList() {
          return new ArrayList<T>();
     }
    

    then

    List<Integer> list = createArrayList();
    

    Which is questionable but works. And maybe pays off well for Maps and other multi-argumented generic types.


    To the edit: maybe the language designers decided to not support generic type inference because they implemented generics with type erasure. An other questionable decision, I think… Otherwise don’t think that there is any serious reason against this feature in earlier java versions. (And by Peter Lawrey’s addendum, it is still not present.)

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

Sidebar

Related Questions

I have a very old project that includes the source from another project directly,
Seems,that very basic question. Anyway can't get the meaning of next definition from Spring
good fellas. I have another very basic question that I need help with. I
I have a very simply question regarding IEquatable. Given the following basic classes: public
I have a very basic question. When I decompile any java class using JAD
I'm struggling with a very basic feature. I want to refer another view from
I'm a perl noob and I have a very basic question regarding the @INC
i have rather very basic question. I have one GUI class and another which
This is another probably very simple question, but I haven't been able to find
This is very similar to another recent question: How can I return the current

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.