Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interface or Concrete class?

user8742475Jan 20 2012 — edited Jan 20 2012
This is my understanding for good Java programming. Can you let me know if it's correct or not please?

In a class, then it's okay to use a concrete class. For example

ArrayList<Car> cars;

In a parameter input of a method, then it's recommended to use an interface for flexibility. For example

public void getCars(List<Car> cars) {

}

or

public void getCars(Collection<Car> cars) {

}

instead of

public void getCars(ArrayList<Car> cars) {

}

Am I correct?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2012
Added on Jan 20 2012
2 comments
53 views