Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

How to use Java generics to avoid ClassCastExceptions from InfoWorld Java

Save for later
  • 1 min read
  • 15 Oct 2020

article-image

Java 5 brought generics to the Java language. In this article, I introduce you to generics and discuss generic types, generic methods, generics and type inference, generics controversy, and generics and heap pollution.

download
Download the source code for examples in this Java 101 tutorial. Created by Jeff Friesen for JavaWorld.

What are generics?

Generics are a collection of related language features that allow types or methods to operate on objects of various types while providing compile-time type safety. Generics features address the problem of java.lang.ClassCastExceptions being thrown at runtime, which are the result of code that is not type safe (i.e., casting objects from their current types to incompatible types).

To read this article in full, please click here

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime