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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:18:24+00:00 2026-05-11T02:18:24+00:00

Most references I’ve seen, and my IDE’s code completion all have my specifying a

  • 0

Most references I’ve seen, and my IDE’s code completion all have my specifying a Generic type on both a variables type and its implementation eg.

List<String> string = new ArrayList<String>(); 

Recently I’ve started skipping the generic type on the implementation eg.

List<String> strings = new ArrayList(); 

assuming that the compiler is only checking against the type for it’s spiffy generics voodoo, and that the implementation shouldn’t care, as its generic types are erased when it’s compiled and should not affect run-time at all.

Am I being naive? Is there a reason to include the generic type on the implementation?

  • 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. 2026-05-11T02:18:24+00:00Added an answer on May 11, 2026 at 2:18 am

    Is there a reason to include the generic type on the implementation?

    It’s required as it won’t necessarily be the same:

    List<? extends Number> numbers = new ArrayList<Integer>(); 

    One way of avoiding it for common cases is to have static utility methods, and let the compiler’s type inference do the rest:

    class CollectionUtilities {    static <T> ArrayList<T> arrayList () { return new ArrayList<T>(); } }  ...  import static CollectionUtilities.*;  List<Integer> numbers = arrayList(); 

    This is type safe, and doesn’t require the generic type on the implementation. (The reason itay’s example is not safe the lack of the generic type on the type of the list variable, not anything to do whether you need to specify generic type on both the variable’s type and the implementation.)

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

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Program { static void Main(string[] args) { Timer timer… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Use GROUP_CONCAT SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo; May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Your code doesn't work because the function is not returning… May 11, 2026 at 10:50 pm

Related Questions

Most references I've seen, and my IDE's code completion all have my specifying a
I recently had to program C++ under Windows for an University project, and I'm
I’ve got a brand new Django project. I’ve added one minimal view function to
I have recently integrated the .NET NLog logging component into one of our applications
For my Programming 102 class we are asked to deliver C code that compiles

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.