Java interface as reference type? [duplicate]
问题 This question already has answers here : What does it mean to “program to an interface”? (31 answers) Closed last year . Where should I use interface as variable type? I see a lot of people say it's best practice to do so, but every example refers to collections: List<String> list = new ArrayList<>() Does this practice apply mostly to collections? I never saw anyone use interface when declaring i/o streams for example. 回答1: The idea is that you want to hide the actual implementation if it isn