Answers for "why cant we have primitive types in generixs"

0

why cant we have primitive types in generixs

//In java generics are implemented by using "Type erasure" for backward compatibility. All generic types are converted to Object at runtime. for example,

public class Container<T> {

    private T data;

    public T getData() {
        return data;
    }
}
//will be seen at runtime as,

public class Container {

    private Object data;

    public Object getData() {
        return data;
    }
}

//Compile ensures cast conversion safety
Posted by: Guest on November-06-2020

Code answers related to "why cant we have primitive types in generixs"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language