From the course: Java: Generic Classes
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Understand type erasure in generics - Java Tutorial
From the course: Java: Generic Classes
Understand type erasure in generics
- [Instructor] Let us now understand what type erasure is. When you write code with generics. And then when you compile that code the generics information is erased or removed. This process is called type erasure. This essentially means that generics provides type safety checks only at the compile time. And this information is not carried in the bytecode that gets executed at runtime. So what really happens in the type erasure process. In this the Java compiler is going to replace your type parameters. And there are two scenarios here. One is when your generic type has unbounded type parameters. In that case the compiler will re place those type parameters with the Object type. The second scenario is when your generic type has bounded type parameters. In that case, the parameters will be replaced with the corresponding bounds. In addition to this, the compiler also ensures that it applies all the appropriate casts…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Generic class hierarchies8m 59s
-
(Locked)
Type argument hierarchies5m 36s
-
(Locked)
Understand type erasure in generics6m 26s
-
(Locked)
Understand bridge methods3m 12s
-
(Locked)
Understand type inference and target types17m 5s
-
Applying wildcard arguments21m 22s
-
(Locked)
Restrictions on generics4m 8s
-
(Locked)
-