liveBook · Manning

Class

As explained in Clojure: The Essential Reference

A Java class is a JVM type definition that specifies the state and behavior of objects and may implement interfaces or extend another class.

In Clojure, class obtains the Java class of an object, making JVM type identity available for interoperability and type checks. It belongs to the Java-oriented side of Clojure’s type and polymorphism facilities. section 15.0 section 15.2

Unlike type, class ignores a value’s :type metadata and reports the underlying Java class. Thus a metadata-tagged vector can have a custom type result while class still returns clojure.lang.PersistentVector. section 15.2

Checking a Java interface

Use instance? when the question is whether an object belongs to a class or implements an interface: (instance? java.lang.Number (bigint 1)) returns true, as does checking 1 against java.lang.Comparable.

How Clojure: The Essential Reference covers it

How deep it goes
Defines class and contrasts it with metadata-aware type, but stops short of detailed JVM class mechanics.
Examples
Uses vectors, strings, functions, nil, metadata-tagged vectors, and Java Number and Comparable checks.
What it assumes
Assumes familiarity with Clojure values, metadata, Java classes, and interfaces.
What you can do after
Diagnose runtime Java types and distinguish underlying classes from metadata-based type labels.
How it connects
Connects class with type, instance?, metadata, Java interfaces, and multimethod dispatch.

Also explained in

Compare how 21 books explain class →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.