Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
fp2025:lab09 [2026/05/16 23:16] silviu |
fp2025:lab09 [2026/05/21 18:08] (current) silviu |
||
|---|---|---|---|
| Line 6: | Line 6: | ||
| * get yourself familiar with covariance and contravariance | * get yourself familiar with covariance and contravariance | ||
| * see the benefits of using these concepts | * see the benefits of using these concepts | ||
| + | * understand bounded generics | ||
| - | *Introduction* | + | **Introduction** |
| When we define a generic type, for example ''Shelter[T]'', and we have a types ''Animal'' and ''Dog'' and ''Dog extends Animal'', the type ''Shelter[Dog]'' does not extend type ''Shelter[Animal]''. However, sometimes we would like to have a conversion in one direction or the other. For example, consider the following code: | When we define a generic type, for example ''Shelter[T]'', and we have a types ''Animal'' and ''Dog'' and ''Dog extends Animal'', the type ''Shelter[Dog]'' does not extend type ''Shelter[Animal]''. However, sometimes we would like to have a conversion in one direction or the other. For example, consider the following code: | ||
| Line 99: | Line 100: | ||
| Notice the invariance of the generic parameter, it will come up in the last exercise. | Notice the invariance of the generic parameter, it will come up in the last exercise. | ||
| - | **9.6.** Apply the ''crossJoinAndFilter'' method on every possible shelter-predicate combination from the previous exercises, note which ones compile and which none don't. | + | **9.6.** Apply the ''crossJoinAndFilter'' method on every possible shelter-predicate combination from the previous exercises, note which ones compile and which ones don't. |
| **9.7.** Complete the following code and use the proper bound and use it on some shelter: | **9.7.** Complete the following code and use the proper bound and use it on some shelter: | ||