Java – the difference between declaring ArrayList under polymorphic and normal conditions?

What is the difference between declaring an ArrayList in such a polymorphism:

List<Integer> iL = new ArrayList<Integer>();

And that normal style:

ArrayList<String> stuff = new ArrayList<String>();

Solution

Yes, a little different

with

List<Integer> iL ;

You can do it

iL = new ArrayList<Integer>();

also

iL = new LinkedList<Integer>();

Benefits:

You can reference any other object as a list

See also

> Liskov substitution principle

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>