|
| 1 | +# <img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=50/>Crazy Generics |
| 2 | +#### Learn tricky nuances and become the master of type parametrization in Java 💪 |
| 3 | + |
| 4 | +### WHY ❓ |
| 5 | +Generics in Java provide **safe type parametrization.** Sou can write the logic of a method or a whole class and |
| 6 | +**reuse it for different types**. Before Java 5 (when generics were introduced), common logic could be reused as well. |
| 7 | +However, it required **using `Object` everywhere and casting it everytime you want to get an actual type**. |
| 8 | +It **could easily cause `ClassCastException` at runtime which is not safe.** When using generics, it's still the same `Object`, |
| 9 | +but **now compiler creates casts for you implicitly, and makes sure you didn't mess up with types**, which **moves errors from |
| 10 | +runtime to compile time and makes type parametrization safer.** |
| 11 | + |
| 12 | +### Objectives |
| 13 | +* create a generic class with **simple type parameter** ✅ |
| 14 | +* create a generic class with **bounded type parameter** ✅ |
| 15 | +* create a generic class with **multiples type parameter** ✅ |
| 16 | +* create a generic class with **recursively bounded type parameter** ✅ |
| 17 | +* create a **generic method** ✅ |
| 18 | +* create a method that accepts a generic class on any type using **wildcard** ✅ |
| 19 | +* create method parameter using **bounded wildcard** ✅ |
| 20 | + |
| 21 | +### Related materials ℹ️ |
| 22 | +* [Effective Java, Chapter 5 – Generics](https://read.amazon.com/kp/embed?asin=B078H61SCH&preview=newtab&linkCode=kpe&ref_=cm_sw_r_kb_dp_SADNB2C41TWARGY4QGKZ) 📘 |
| 23 | + |
| 24 | + |
| 25 | +--- |
| 26 | +#### 🆕 First time here? – [See Introduction](https://github.com/bobocode-projects/java-fundamentals-course/tree/main/0-0-intro#introduction) |
| 27 | +#### ➡️ Have any feedback? – [Please fill the form ](https://forms.gle/UADe1YKHiFVXQJLF8) |
| 28 | + |
0 commit comments