Clojure - 找不到匹配的方法

Clojure - No matching method found

不明白为什么 clojure 告诉我找不到这个函数名。我正在尝试调用 setProperties function on a CloudBlockBlob, which inherits from CloudBlob.

(ns my-ns.infra.azure-blob
  (:import (com.microsoft.azure.storage.blob
             CloudBlob
             CloudBlockBlob
             CloudBlobClient
             CloudBlobContainer
             BlobContainerPublicAccessType
             BlobRequestOptions BlobProperties CloudBlob BlobContainerProperties)
           (com.microsoft.azure.storage
             CloudStorageAccount
             OperationContext
             )))

(def blob (-> "img-manip"
           get-container-cached
           (.getBlockBlobReference "some-file.txt")))


(def props (-> blob
           .getProperties))

clojure怎么看setProperties函数?通过clojure.reflect/reflect--

#clojure.reflect.Method{:name setProperties,
                                    :return-type void,
                                    :declaring-class com.microsoft.azure.storage.blob.CloudBlob,
                                    :parameter-types [com.microsoft.azure.storage.blob.BlobProperties],
                                    :exception-types [],
                                    :flags #{:final :protected}}

blob 可以转换为 CloudBlob 吗?是:

(cast com.microsoft.azure.storage.blob.CloudBlob blob)
=>
#object[com.microsoft.azure.storage.blob.CloudBlockBlob
        0x7f613b97
        "com.microsoft.azure.storage.blob.CloudBlockBlob@7f613b97"]

我的属性是 BlobProperties 吗?是:

(cast com.microsoft.azure.storage.blob.BlobProperties props)
=>
#object[com.microsoft.azure.storage.blob.BlobProperties
        0x55cd6938
        "com.microsoft.azure.storage.blob.BlobProperties@55cd6938"]

当我调用 .setProperties 时会发生什么?

(.setProperties blob props)
     java.lang.IllegalArgumentException: No matching method found: setProperties for class com.microsoft.azure.storage.blob.CloudBlockBlob
clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: No matching method found: setProperties for class com.microsoft.azure.storage.blob.CloudBlockBlob, compiling:(/Users/micahsmith/printio/gooten-preview/gooten-preview-api/src/gooten_preview_api/infra/azure_blob.clj:72:1)

没看懂

setProperties 是一个 protected 方法:

protected final void setProperties(final BlobProperties properties) {
    this.properties = properties;
}

如果 setProperties 是一个 public 方法,那么您正在做的事情就会起作用。您可以通过在 Clojure 项目中定义类似的 类 来重现此内容:

public abstract class Vehicle {
    public final void go(int miles) {
    }
}
public class MonsterTruck extends Vehicle { }

在 Clojure 中:

(def truck (MonsterTruck.))
(.go truck 1) ;; resolves base class method, works

但是如果您将 go 更改为 protected final void,您将看到与您遇到的相同的错误。