Z
zapanaz_googlegroups
I have a parent class, AddressInfo. An abstract class. Two classes inherit from AddressInfo, ShippingInfo and BillingInfo. ShippingInfo and BillingInfo are nearly identical, and are identical for what I'm doing here.
The example code I'm posting is stripped down, in case you wonder why it's a little dumb.
I have two methods,
public void mergeBillingInfoLists(List<BillingInfo> list1, List<BillingInfo> list2) {
list1.add(1, list2.get(0));
}
And one for ShippingInfo which is identical, just with ShippingInfo where BillingInfo is.
I want to combine the two methods, which are very redundant. It seems like it should be possible, given that they have a common parent class. I can dothis:
public void mergeAddressInfo(List<? extends AddressInfo> list1, List<? extends AddressInfo> list2) {
list1.add(1, list2.get(0));
}
But Java won't allow this, it won't allow the add(). All it knows about what list2 contains is that it's something that descends from AddressInfo, so even if I pass in 2 List<BillingInfo>'s, inside the code it doesn't know they're the same classes.
Does anybody offhand know a way to do this? (Without throwing away the parameterization )
I don't necessarily need to use this exact approach, just anything that would allow me to combine the two methods into one method. In fact I have quite a lot of this kind of redundancy in the code base I'm working with, so this is something I'm running into a lot.
Thanks for any help
--
Joe Cosby
http://joecosby.com/
`She knew how to embroider and milk a cow.' -- Connie Willis, Doomsday Book
:: Currently listening to Oxygene, Pt. II, 1976, by Jean Michel Jarre, from"Oxygene"
The example code I'm posting is stripped down, in case you wonder why it's a little dumb.
I have two methods,
public void mergeBillingInfoLists(List<BillingInfo> list1, List<BillingInfo> list2) {
list1.add(1, list2.get(0));
}
And one for ShippingInfo which is identical, just with ShippingInfo where BillingInfo is.
I want to combine the two methods, which are very redundant. It seems like it should be possible, given that they have a common parent class. I can dothis:
public void mergeAddressInfo(List<? extends AddressInfo> list1, List<? extends AddressInfo> list2) {
list1.add(1, list2.get(0));
}
But Java won't allow this, it won't allow the add(). All it knows about what list2 contains is that it's something that descends from AddressInfo, so even if I pass in 2 List<BillingInfo>'s, inside the code it doesn't know they're the same classes.
Does anybody offhand know a way to do this? (Without throwing away the parameterization )
I don't necessarily need to use this exact approach, just anything that would allow me to combine the two methods into one method. In fact I have quite a lot of this kind of redundancy in the code base I'm working with, so this is something I'm running into a lot.
Thanks for any help
--
Joe Cosby
http://joecosby.com/
`She knew how to embroider and milk a cow.' -- Connie Willis, Doomsday Book
:: Currently listening to Oxygene, Pt. II, 1976, by Jean Michel Jarre, from"Oxygene"