1. Overview

Sometimes we need to determine if an object is of primitive type, especially for wrapper primitive types. However, there are no built-in methods in the standard JDK to achieve this.

In this quick tutorial, we’ll see how to implement a solution using core Java. Then we’ll take a look at how we can achieve this using a couple of commonly used libraries.

2. Primitives and Wrapper Classes

There are nine predefined objects to represent eight primitives and a _void _type in Java. Each primitive type has a corresponding Wrapper Class.

To learn more about Primitives and _Object_s, please see this article.

The java.lang.Class.isPrimitive() method can determine if the specified object represents a primitive type. However, it does not work on the wrappers for primitives.

#java #core java

Determine if an Object is of Primitive Type
1.05 GEEK