使用代理时,为什么clojure会出现java.lang.IllegalAccessError错误

时间:2016-09-12 10:59:44

标签: clojure interface twitter4j

我正在尝试使用Twitter4j来访问用户流。我遇到的问题是我无法实现接口,然后将其用作监听器。

这是我的完整代码

(ns dameon.temporal-lobe.twitter
      (:import [twitter4j TwitterStreamFactory StatusListener StreamListener]
               [twitter4j.conf ConfigurationBuilder])
      (:require [clojure.edn :as edn :only [read-string]]))



;;The class that handles the stream data
(def status-listener
  (proxy [StatusListener] []
   (onStatus [status]
     (println status))
   (onDeletionNotice [status-deletion-notice])
   (onTrackLimitationNotice [number-of-limited-statuses])
   (onStallWarning [warning])
   (onException [ex]
     (.printStackTrace ex))
   (onScrubGeo [user-id up-to-status-id])))

(class status-listener)

;;Connect to the stream and add listener
(def creds (get (edn/read-string (slurp "creds.edn")) :twitter))

(-> (ConfigurationBuilder.)
    (.setDebugEnabled true)
    (.setOAuthConsumerKey (creds :consumer-key))
    (.setOAuthConsumerSecret (creds :consumer-secret))
    (.setOAuthAccessToken  (creds :access-token))
    (.setOAuthAccessTokenSecret (creds :access-secret))
    (.build)
    (TwitterStreamFactory.)
    (.getInstance)
    (.addListener status-listener)
    (.sample))

这是我得到的错误

 Unhandled java.lang.IllegalAccessError
   tried to access class twitter4j.StreamListener from class
   dameon.temporal_lobe.twitter$eval11235

这是为什么?这些接口不是私有的。它们只是简单的界面。发生了什么事?

1 个答案:

答案 0 :(得分:1)

假设this is the implementationtwitter4j.StreamListener声明没有显式访问修饰符,因此它只在自己的包中可见 - 请参阅Gosling,Joy,Steele,Bracha,Buckley,The Java ® Language Specification. Java SE 8 Edition ,§6.6.1确定可访问性:

  

如果类或接口类型被声明为public,则任何代码都可以访问它,前提是声明它的编译单元(第7.3节)是可观察的。

     

如果使用包访问声明了类或接口类型,则只能从声明它的包中访问它。

     

声明没有访问修饰符的类或接口类型隐式具有包访问权。