Categories: ProgrammingNews

How to use Java generics to avoid ClassCastExceptions from InfoWorld Java

1 min read

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

Matthew Emerick and Oli Huggins

Share
Published by
Matthew Emerick and Oli Huggins
Tags: Java

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago