why cant we have primitive types in generixs

Solutions on MaxInterview for why cant we have primitive types in generixs by the best coders in the world

showing results for - "why cant we have primitive types in generixs"
Damián
31 Jun 2017
1//In java generics are implemented by using "Type erasure" for backward compatibility. All generic types are converted to Object at runtime. for example,
2
3public class Container<T> {
4
5    private T data;
6
7    public T getData() {
8        return data;
9    }
10}
11//will be seen at runtime as,
12
13public class Container {
14
15    private Object data;
16
17    public Object getData() {
18        return data;
19    }
20}
21
22//Compile ensures cast conversion safety
similar questions