What is the difference between a primitive class and primitive data type?

Luke Thistlethwaite :

I am reading a book on Java, and they seem to use the two terms "primitive class" and "primitive data type" interchangeably.

What's the difference between the two? I understand that Integer is a wrapper class, and people reference int as a primitive data type. So is it also a primitive class?

Makoto :

They're confusing their vernacular here.

A primitive is a data type which is not an object. int, float, double, long, short, boolean and char are examples of primitive data types. You can't invoke methods on these data types and they don't have a high memory footprint, which is their striking difference from classes.

Everything else is a class (or class-like in the case of interfaces and enums). Pretty much everything that begins with an upper-case letter, like String, Integer are classes. Arrays also classify as not-primitives, even though they may hold them. int[] isn't a primitive type but it holds primitives.

The only thing that could realistically come close would be the wrapper classes, as explained by the JLS, but even then, they're still classes, and not primitives.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=475052&siteId=1