Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure a clojure variable is of the right Java type

java-code XSSFRow row = sheet.getRow(p);
clojure-code (def row (.getRow sheet p))
How do we make sure that row is of type XSSFRow ?

like image 768
vikbehal Avatar asked Jan 27 '26 01:01

vikbehal


1 Answers

Clojure is dynamically typed, so the type of a var/value is determined at runtime.

If you want to make sure a value is of a certain class, you could make the following assertion:

(assert (= (class row) XSSFRow))

Or, more concisely (thanks to opqdonut):

(assert (instance? XSSFRow row))

This does not check for exact class, but for any superclass:

(instance? Object row) ;=> true
like image 187
Christian Berg Avatar answered Jan 28 '26 17:01

Christian Berg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!