无法弄清楚clojure为什么告诉我找不到此函数名称。我试图在setProperties的CloudBlockBlob, which inherits上调用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)
我不明白。
答案 0 :(得分: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
,将会看到相同的错误。