Java Interview Question

Use this advanced question and answer to prepare for your next Java interview.

What is type erasure?

The Type information used for Generic objects is only available at compile time. The compiler removes all the type information when converting to byte-code. This makes the type information unavailable at Runtime and the Generic type is converted to Raw type. The compiler provides checks at compile time to prevent runtime errors for incorrect type information.

The case where things can go wrong is when directly using Raw types in the code. The compiler will raise a warning in this case but it will not fail.

Looking for developers?

Want to learn more about Gigster? Enter your email and we'll be in touch.