Clojure 1.8参考手册
Clojure 1.8
clojure.reflect
完整的命名空间名称:clojure.reflect
概述
Reflection on Host Types
Alpha - subject to change.
Two main entry points:
* type-reflect reflects on something that implements TypeReference.
* reflect (for REPL use) reflects on the class of an instance, or
on a class if passed a class
Key features:
* Exposes the read side of reflection as pure data. Reflecting
on a type returns a map with keys :bases, :flags, and :members.
* Canonicalizes class names as Clojure symbols. Types can extend
to the TypeReference protocol to indicate that they can be
unambiguously resolved as a type name. The canonical format
requires one non-Java-ish convention: array brackets are <>
instead of [] so they can be part of a Clojure symbol.
* Pluggable Reflectors for different implementations. The default
JavaReflector is good when you have a class in hand, or use
the AsmReflector for "hands off" reflection without forcing
classes to load.
Platform implementers must:
* Create an implementation of Reflector.
* Create one or more implementations of TypeReference.
* def default-reflector to be an instance that satisfies Reflector.
在Clojure版本1.3中添加
协议
ClassResolver协议
已知实现:clojure.lang.Fn,java.lang.ClassLoader
解析类函数
Usage: (resolve-class this name)
Given a class name, return that typeref's class bytes as an InputStream.
来源
反射协议
Protocol for reflection implementers.
已知实现:AsmReflector,,,JavaReflector
DO反射函数
Usage: (do-reflect reflector typeref)
来源
类型参考协议
A TypeReference can be unambiguously converted to a type name on
the host platform.
All typerefs are normalized into symbols. If you need to
normalize a typeref yourself, call typesym.
已知实现:clojure.asm.Type,clojure.lang.Symbol,java.lang.Class
类型函数
Usage: (typename o)
Returns Java name as returned by ASM getClassName, e.g. byte[], java.lang.String[]
来源
类型
AsmReflectortype
字段:类解析器
议定书:反射器
接口:
建筑记录
字段:名称声明类参数类型异常类型标志
议定书:
接口:clojure.lang.IHashEq,clojure.lang.IKeywordLookup,clojure.lang.ILookup,clojure.lang.IObj,clojure.lang.IPersistentMap,java.ios.erialable,java.util.Map
场记录
字段:名称类型声明-类标志
议定书:
接口:clojure.lang.IHashEq,clojure.lang.IKeywordLookup,clojure.lang.ILookup,clojure.lang.IObj,clojure.lang.IPersistentMap,java.ios.erialable,java.util.Map
JavaReflectortype
字段:类装入器
议定书:反射器
接口:
方法记录
字段:名称返回类型声明类参数类型异常类型标志
议定书:
接口:clojure.lang.IHashEq,clojure.lang.IKeywordLookup,clojure.lang.ILookup,clojure.lang.IObj,clojure.lang.IPersistentMap,java.ios.erialable,java.util.Map
公共变量和函数
->AsmReflectorfunction
Usage: (->AsmReflector class-resolver)
Positional factory function for class clojure.reflect.AsmReflector.
来源
->构造函数
Usage: (->Constructor name declaring-class parameter-types exception-types flags)
Positional factory function for class clojure.reflect.Constructor.
来源
->场函数
Usage: (->Field name type declaring-class flags)
Positional factory function for class clojure.reflect.Field.
来源
->Java反射器函数
Usage: (->JavaReflector classloader)
Positional factory function for class clojure.reflect.JavaReflector.
来源
->方法功能
Usage: (->Method name return-type declaring-class parameter-types exception-types flags)
Positional factory function for class clojure.reflect.Method.
来源
标志描述符
The Java access bitflags, along with their friendly names and
the kinds of objects to which they can apply.
来源
映射->构造函数
Usage: (map->Constructor m#)
Factory function for class clojure.reflect.Constructor, taking a map of keywords to field values.
来源
映射->场函数
Usage: (map->Field m#)
Factory function for class clojure.reflect.Field, taking a map of keywords to field values.
来源
MAP->方法函数
Usage: (map->Method m#)
Factory function for class clojure.reflect.Method, taking a map of keywords to field values.
来源
反射函数
Usage: (reflect obj & options)
Alpha - subject to change.
Reflect on the type of obj (or obj itself if obj is a class).
Return value and options are the same as for type-reflect.
在Clojure版本1.3中添加
来源
类型反射函数
Usage: (type-reflect typeref & options)
Alpha - subject to change.
Reflect on a typeref, returning a map with :bases, :flags, and
:members. In the discussion below, names are always Clojure symbols.
:bases a set of names of the type's bases
:flags a set of keywords naming the boolean attributes
of the type.
:members a set of the type's members. Each member is a map
and can be a constructor, method, or field.
Keys common to all members:
:name name of the type
:declaring-class name of the declarer
:flags keyword naming boolean attributes of the member
Keys specific to constructors:
:parameter-types vector of parameter type names
:exception-types vector of exception type names
Key specific to methods:
:parameter-types vector of parameter type names
:exception-types vector of exception type names
:return-type return type name
Keys specific to fields:
:type type name
Options:
:ancestors in addition to the keys described above, also
include an :ancestors key with the entire set of
ancestors, and add all ancestor members to
:members.
:reflector implementation to use. Defaults to JavaReflector,
AsmReflector is also an option.
在Clojure版本1.3中添加
来源
Clojure 1.8相关
Clojure 是一种运行在 Java 平台上的 Lisp 方言,Lisp 是一种以表达性和功能强大著称的编程语言,但人们通常认为它不太适合应用于一般情况,而 Clojure 的出现彻底改变了这一现状。如今,在任何具备 Java 虚拟机的地方,您都可以利用 Lisp 的强大功能。
版本 | 1.8 |
发布版本 | 1.8 |