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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:28:05+00:00 2026-05-24T07:28:05+00:00

Java’s generics would erase the type information after the source code was compiled. And

  • 0

Java’s generics would erase the type information after the source code was compiled. And i guess the “erase” is necessary because java only keep one copy of class no matter what the generic type is. So List<String> or List<Number> are simply just one List. Then I wonder if it possible that at the premise of keeping only one copy of certain class, the instance of the class stores the generic type information at the time it is created.

For instance:
when we write:

List<String> list = new List<String>. 

the compiler create an object of List along with a String’s Class Object(meaning the Object String.class) accociated with the List, so that the generic object list can check the type information at runtime using the Class Object. Is it posssible or practicable?

  • 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-05-24T07:28:06+00:00Added an answer on May 24, 2026 at 7:28 am

    I’m not entirely sure what you’re asking specifically, but the big reason Java has to use erasure for generics is backwards compatibility. If the behaviour of

    List list = new ArrayList(); //You can't do new list(), it's an interface
    

    …was altered between versions, when you upgraded from say Java 1.4 to Java 5, you’d have all sorts of weird things going on potentially causing bugs where the code didn’t behave in the same way as previously. That’s definitely a bad thing if that happens!

    If they didn’t have to preserve backwards compatibility then yes, they could’ve done what they liked – we could’ve had nice reified generics and done a whole bunch of other stuff we couldn’t do now. There was a proposal (by Gafter I think) that would’ve allowed reified generics in Java in a backwards compatible way, but it would’ve involved creating new versions of all the classes that should have been generic. That would’ve caused a load of mess with the API, so (for better or worse) they chose not to go down that route.

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

Sidebar

Related Questions

Java uses a combination of compilation and interpretation. It compiles the source code into
Java generics are implemented using type erasure. That means that if I have a
java.lang.NullPointerException at java.lang.Integer.compareTo(Unknown Source) at java.lang.Integer.compareTo(Unknown Source) I slightly edited my code, deleted no
Java has generics and C++ provides a very strong programming model with template s.
Java SE 6 (64 bit only) is now on OS X and that is
Java Code: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( http://localhost/SC/upload.php); FileBody
Java code: import javax.swing.Timer; class Main { public static void main(String args[]) { MyListener
Java 5 introduced generics, and they were added to many interfaces in the java.lang
java.util.concurrent API provides a class called as Lock , which would basically serialize the
java.math.MutableBigInteger is only available from inside the package. It inherits from java.lang.Object and there

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.