如何在clojure中实例化Stream.Builder类? (使用java 9)

时间:2018-03-30 12:24:27

标签: clojure

我按照此示例启动Stream.Builder:

http://www.java2s.com/Tutorials/Java/java.util.stream/Stream.Builder/Stream.Builder.build_.htm

Intent

但是,我得到了这个:

private static final String isSharedElementTransitionEnabled = "IS_SHARED_ELEMENT_TRANSITION_ENABLED";    

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_b);

    // If you are postponing your SharedElementTransition, don't forget to call postponeEnterTransition() and override onPreDraw()

    if (!getIntent().getExtras().getBoolean(isSharedElementTransitionEnabled)) {
        //Do your UI updation here
    }
}

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:2)

快速的研究让我想到了这个问题: https://dev.clojure.org/jira/browse/CLJ-2284

所以解决方法如前所述:

(import 'java.util.stream.Stream)

(defmacro interface-static-call
  [sym & argtypes]
  `(let [m# (.getMethod ~(symbol (namespace sym))
                        ~(name sym)
                        (into-array Class ~argtypes))]
     (fn [& args#]
       (.invoke m# nil (to-array args#)))))

(doto ((interface-static-call Stream/builder))
  (.accept "a")
  (.accept "b")
  (.accept "c")
  (.accept "d")
  (.accept "e"))

;;=> #object[java.util.stream.Streams$StreamBuilderImpl 0x121300ed "java.util.stream.Streams$StreamBuilderImpl@121300ed"]

在java 9上为我工作

所以我想我们应该等待clojure修复。