Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #primitive #types #generixs
ADD COMMENT
Topic
Name
3+2 =