Why are variables declared with their interface name in Java? [duplicate]
问题 This question already has answers here : What does it mean to “program to an interface”? (31 answers) Closed 2 years ago . This is a real beginner question (I\'m still learning the Java basics). I can (sort of) understand why methods would return a List<String> rather than an ArrayList<String>, or why they would accept a List parameter rather than an ArrayList. If it makes no difference to the method (i.e., if no special methods from ArrayList are required), this would make the method more