Fork me on GitHub
#other-languages
<
2020-11-06
>
Jim Newton13:11:12

Any Scala programmers? Does anyone know how to get the :flags and :members information returned from clojure.reflect/type-reflect within a Scala program? I have some class reflection code in Clojure, that I'd like to convert to Scala.

andy.fingerhut15:11:54

clojure.reflec/type-reflect at the 'bottom' is making calls to the Java Reflection API, and then turning the results into Clojure maps. For example, on a JVM object with type Class, you can get an integer using the method getModifiers: https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getModifiers-- and then documented bit positions in that integer represent each of the possible flags like public, abstract, etc. If you know the Java calls that can do it, and know the rules for Scala syntax of calls to Java methods, that will get you what you want, but I don't have interest in learning the Scala syntax of Java method calls to help you with that part. The Java method calls that Clojure uses could be gleaned from a careful reading of its implementation of the type-reflect function, but if I recall correctly it is spread over several different functions in Clojure's core library.