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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:31:56+00:00 2026-05-25T12:31:56+00:00

I was going through TypeErasure topic at http://download.oracle.com/javase/tutorial/java/generics/erasure.html which says that compiler removes all

  • 0

I was going through TypeErasure topic at http://download.oracle.com/javase/tutorial/java/generics/erasure.html which says
that compiler removes all information related to type parameters and type arguments within a class or method.

Now considering the code below

public class Box<T> {
    private T t; // lineA, T stands for "Type" 

    public void add(T t) { // lineB
        this.t = t; // lineC
    }

    public T get() { // lineD
        return t; // lineE
    }
}

Now inside main method I have below code snippet

Box<String> box1 = new Box<String>(); // line1
box1.add("Scott"); // line2
String s1tr=box1.get(); // line3

Box<Integer> box2 = new Box<Integer>(); // line4
box2.add(1); // line5
Integer k=box2.get(); // line6

Now in above code (in Box class and main method) what are the changes compiler will make and at which line?

As the link says that compiler removes all information related to type parameters and type arguments within a class or method, when compiler
will compile Box class, will it remove all T,<String>,<Integer> occurences from Box class and main method respectively? If yes, what will be the compiled code after Removing T?

  • 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-25T12:31:57+00:00Added an answer on May 25, 2026 at 12:31 pm

    Type erasure happens at compile time. Java compiler removes those generic type information from source and adds casts as needed and delivers the byte code. Therefore the generated byte code will not have any information about type parameters and arguments. It will look like a old java code without generics. There is no way to determine the value of T at runtime, because that information is removed before the code is compiled.

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

Sidebar

Related Questions

After going through the article at http://geekexplains.blogspot.com/2008/06/diff-between-externalizable-and.html , i got to know Externalizable is
While Going through the java tutorial on sun site, I see following piece of
Going through the tutorial here: http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs I've noticed that they are passing the EF
After going through so many documents and online content like: http://stackoverflow.com/questions/4066167/sencha-touch-or-jquery-mobile http://stackoverflow.com/questions/5093691/sencha-touch-vs-jqtouch-vs-gwt-mobile-vs-xui-vs-jquery-mobile-vs http://www.quora.com/Were-deciding-between-jQuery-Mobile-currently-in-alpha-and-Sencha-Touch-What-are-the-pros-and-cons-for-each http://interfacethis.com/2011/adventures-in-html5-part-one/
I'm going through the full tutorial at cplusplus.com, coding and compiling each example manually.
Going through the microsoft authentication tutorial listed here they have you create a master
Going through the Symblog tutorial of Symfony2, While creating forms I came to a
Going through Lynda's 2010 tutorial on rails and have been stuck on migration for
Going through the SproutCore Getting started tutorial and have a problem. Inside the Todos.todoListController
Going through the php.net site, it had an example for header, which says would

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.