Java Generic Cache Implementation

Problem

Given the cache interface below

We want to implement a generic cache class in order to improve compile time type checking.

Solution

Using Java Generics one can provide variable types as parameters for compile time type checking. In this case we are going to use K for key and V for value as follows

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *