Program JavaZone

Lyntale Torsdag 3. september

Generics – You Never Know What You’re Gonna Get

Room 6

Engelsk 20 min generics type erasure covariant contravariant subtype

Bram Janssens

Hello, I'm Bram Janssens, I work as a trainer/consultant in The Netherlands. Throughout my career, I’ve alternated between teaching and software engineering—but at heart, I consider myself a teacher. I enjoy helping others, explaining complex topics clearly, and making a meaningful difference.

My motto: "Actually, it’s quite simple!"

While I'm happy to support others in any subject, my technical expertise lies in Java, thanks to years of hands-on experience. I'm also enthusiastic about Kotlin and enjoy exploring its modern features.

In my free time, I enjoy playing tennis, doing pub quizzes, brewing beer, and umpiring baseball.

📇 Digital business card: bramjanssens.nl

You might think Java is type-safe, but did you know you can *break* type safety too? It all comes down to variance: co-, contra-, and invariance.

Maybe you’ve heard of these terms, but you’re not entirely sure what they mean or how to use them effectively. That was exactly my situation — even after more than ten years of experience with Java. I’ve noticed this same knowledge gap among the students I teach.

Type safety gives us reliability but also adds complexity compared to weakly, dynamically typed languages. Why do we even have types? What makes something a subtype? Do you think you can pass an `Integer` into a parameter of type `Number`? And what about a “type that has a type”? Generics are Java’s way of handling such cases, but they can introduce unexpected and sometimes seemingly illogical behavior. For example: Can you pass a `List<Integer>` into a parameter of type `List<Number>`? What is a capture, and why do you sometimes see errors like "`add(capture of ? extends A)` cannot be applied to `S`"?

In this talk, I’ll demystify these concepts and explain them in a way you’ll never forget. You’ll impress your colleagues, gain a competitive edge, and be better prepared to understand and write reusable (framework) code.

Attendees will walk away with not just understanding, but confidence—and a new ability to write safer, more expressive code. Moderate experience with Java is recommended.

  1. Understanding Prompt Injection - Techniques, Challenges, and Advanced Escalation Room 1
  2. Kodearkeologer på legacy eventyr Room 2
  3. Spring: Spock vs. Kotest vs. JUnit - When to Pick Which One? Room 3
  4. Stop writing Terraform: Build developer-friendly platforms with Crossplane Room 4
  5. A Journey - On tour with Java code on it’s way through the JVM Room 7
  6. How to Git Away with Murder Room 8