课程: Java: Advanced Concepts for High-Performance Development

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using wildcards in generic programming

Using wildcards in generic programming

- [Instructor] In the previous video, we saw how the substitution principle can help us write clean code, but it's also important to know when the principle doesn't apply. So, in this ClothingSite class, I've got my main method and inside that I'm creating two objects, a ShirtItem and a JacketItem. And ShirtItem and JacketItem both extends the ClothingItem class. And then I'm creating an array list containing ClothingItems and I'm adding the shirtItem and the jacketItem to that list. And then finally, I'm calling the checkoutAllItems method and I'm passing in my list of clothingItems. And in the checkoutAllItems method I'm iterating over that list. And for each one, I'm checking out the item. But let's say, I want to create a list that just contains ShirtItems and not JacketItems. So, I'm going to change this JacketItem to another ShirtItem, and I'll call it shirtItem2. And on the right hand side…

内容