What is meant by parameterized type?

They are both parameterized types: types that take other types as parameters.

The fact that you have different types on the two sides of the expression is irrelevant, and has to do with polymorphic behavior i.e. because LinkedList is a subtype of Collection.


Parameterized type generally is a class that deals with other object without interesting what type is it. The type may be defined using symbolic "name" and then passed when instance of class is created.

For example:

class MyClass<T> {
    private T obj;
    public MyClass<T>(T obj) {
        this.obj = obj;
    }
    public int getId() {
        return obj.hashCode();
    }
}

In example above MyClass wraps object of any type and executes its method hashCode() using the fact that this method always exists.

Here is how this class is used:

int sid = new MyClass<String>("aaaa").hashCode();

Please pay attention that you cannot say new MyClass<String>(123): the fact that object is created with parameter String dictates the type of constructor argument.

Coming back to your example Collection<String> means "collection of strings". This means that you cannot add object of other type to this collection.

Tags:

Java

Generics