This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-26
Channels
- # announcements (3)
- # babashka (28)
- # beginners (21)
- # cider (29)
- # clojars (10)
- # clojure (14)
- # clojure-australia (3)
- # clojure-europe (48)
- # clojure-nl (3)
- # clojure-sanfrancisco (4)
- # clojure-uk (54)
- # clojurescript (34)
- # cryogen (12)
- # cursive (7)
- # datomic (14)
- # devcards (1)
- # fulcro (23)
- # helix (2)
- # java (5)
- # jobs (1)
- # kaocha (15)
- # malli (13)
- # minimallist (1)
- # off-topic (8)
- # pathom (7)
- # pedestal (1)
- # rdf (10)
- # reagent (18)
- # shadow-cljs (58)
- # spacemacs (3)
- # tools-deps (1)
- # vim (6)
- # xtdb (37)
When I use the Java reflection API to get information about all methods and fields of the interface clojure.lang.IPersistentVector, e.g. using code in the REPL like this:
(require '[clojure.reflect :as refl])
(require '[clojure.pprint :as pp])
(def t1 (refl/type-reflect clojure.lang.IPersistentVector))
(pp/pprint t1)
I see not only the methods that are explicitly declared in that interface here: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IPersistentVector.java
I also see a fourth method named cons
that has the flags :public :bridge :synthetic
that has :return-type clojure.lang.IPersistentCollection
. My guess is that this is somehow because IPersistentVector extends IPersistentStack, which in turn extends IPersistentCollection, which has its own cons
method.
The Java Virtual Machine Specification for Java SE 8 says that the bridge flag for a method means "A bridge method, generated by the compiler.", and the synthetic flag means "Declared synthetic; not present in the source code." (see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6).
Hmmm, I was going to say I had not found much in the way of explanation for why this happens, but this may be a case of rubber ducking, as I am perhaps doing different Google searches now than I was earlier when I tried to learn what is going on. This article might be explaining what is going on: http://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html#:~:text=Bridge%20methods%20in%20Java%20are,the%20actual%20method%20being%20invoked.