【问题标题】:Method cannot be found but clojure.reflector shows otherwise找不到方法,但 clojure.reflector 以其他方式显示
【发布时间】:2017-03-12 17:19:18
【问题描述】:

我正在尝试使用 hapi fhir 从 clojure 创建一个 dstu2 客户端。作为模板,我使用https://github.com/jamesagnew/hapi-fhir/blob/master/examples/src/main/java/example/GenericClientExample.java

但我无法执行

ctx.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING);
in clojure

我要做的是:

(def fhir-context (. FhirContext forDstu2))
=> #'emrspp.fhir-resources/fhir-context 
(def opts PerformanceOptionsEnum/DEFERRED_MODEL_SCANNING)
=>  #'emrspp.fhir-resources/opts 

但随后以下失败:

(.setPerformanceOptions fhir-context opts)
=>
CompilerException java.lang.IllegalArgumentException: No matching method found: setPerformanceOptions for class ca.uhn.fhir.context.FhirContext

clojure 反射给出以下结果:

(pprint (filter #(= "setPerformanceOptions" (str (:name %))) (:members  (r/reflect fhir-context))))

=> 
~
({:name setPerformanceOptions,
  :return-type void,
  :declaring-class ca.uhn.fhir.context.FhirContext,
  :parameter-types [ca.uhn.fhir.context.PerformanceOptionsEnum<>],
  :exception-types [],
  :flags #{:varargs :public}}
 {:name setPerformanceOptions,
  :return-type void,
  :declaring-class ca.uhn.fhir.context.FhirContext,
  :parameter-types [java.util.Collection],
  :exception-types [],
  :flags #{:public}})
nil

导入部分是:

 (:import [org.hl7.fhir.instance.model.api IBaseOperationOutcome IBaseResource ]
  7            [ca.uhn.fhir.context FhirContext PerformanceOptionsEnum]
  8            [ca.uhn.fhir.model.base.resource BaseOperationOutcome ]
  9            [ca.uhn.fhir.model.dstu2.resource Bundle
 10                                              Conformance Observation
 11                                              OperationOutcome
 12                                              Organization Parameters
 13                                              Patient Provenance]
 14            [ca.uhn.fhir.model.dstu2.valueset AdministrativeGenderEnum IssueSeverityEnum]
 15             [ca.uhn.fhir.model.primitive DateDt IdDt  InstantDt]
 16            [ca.uhn.fhir.rest.api  MethodOutcome SummaryEnum ]
 17            [ca.uhn.fhir.rest.client IGenericClient ServerValidationModeEnum interceptor.LoggingInterceptor ]
 18            [ca.uhn.fhir.rest.method.SearchStyleEnum ]
 19            [ca.uhn.fhir.rest.param.DateRangeParam ]
 20            [ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException ]
 21            )

除了 pprint 和反射之外没有 :requires

任何关于 setPerformanceOptions 方法似乎存在但被执行的事件??

【问题讨论】:

    标签: clojure clojure-java-interop dstu2-fhir


    【解决方案1】:

    我在几个小时后想通了。我仔细看看命名空间:http://hapifhir.io/apidocs/ca/uhn/fhir/context/FhirContext.html 表明传递的参数需要是一个 java 集合,因此

    (.setPerformanceOptions fhir-context opts)
    

    必须改为

    (.setPerformanceOptions fhir-context (java.util.ArrayList. [opts]))
    

    或者更简单

    (.setPerformanceOptions fhir-context [opts] )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      相关资源
      最近更新 更多