Why does arraylist class implement List as well as extend AbstractList?

后端 未结 8 2086
青春惊慌失措
青春惊慌失措 2020-12-05 02:29

The implementation of java.util.ArrayList implements List as well as extends AbstractList. But in java docs you can see that AbstractL

8条回答
  •  旧时难觅i
    2020-12-05 03:00

    1) ArrayList implements List is redundant but still legal. Only JCF (Java Collection Framework) designers could answer why. Since the lead JCF designer J.Bloch does not say why it's like this in "Effective Java" it seems we will never know why.

    2) Arrays.asList returns

    public class Arrays {
       ...
    
        private static class ArrayList extends AbstractList
            implements RandomAccess, java.io.Serializable
        {
    ...
    

    it's not java.util.ArrayList and it cannot be cast to it

提交回复
热议问题