Twitter 发布了一个 Java 客户端库,并包含以下使用它的示例代码:
// Connect to the filter endpoint, tracking the term "twitterapi"
Hosts host = new BasicHost(Constants.STREAM_HOST);
StreamingEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.trackTerms(Lists.newArrayList("twitterapi"));
// Drop in the oauth credentials for your app, available on dev.twitter.com
Authentication auth = new OAuth1("consumerKey", "consumerSecret",
"token", "tokenSecret");
// Initialize a queue to collect messages from the stream
BlockingQueue<String> messages = new LinkedBlockingQueue<String>(100000);
// Build a client and read messages until the connection closes.
ClientBuilder builder = new ClientBuilder()
.name("FooBarBaz-StreamingClient")
.hosts(host)
.authentication(auth)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(messages));
Client client = builder.build;
client.connect();
while (!client.isDone()) {
String message = messages.take();
// Do something with message
}
发布公告:https://dev.twitter.com/blog/the-hosebird-client-streaming-library
尖括号是什么意思?
最佳答案
BlockingQueue<String>
的超接口(interface)之一是集合。
这意味着它实现了 java.util.Collection
的功能它使您有可能使用泛型并使集合强制保存!
使用通用的:
BlockingQueue<String>
您只能在 BlockingQueue 中使用 String。 尝试添加另一个值,您的 IDE 会通知您不匹配。这是一个很大的好处,因为检查不是在您的应用程序运行时完成的。
关于java - 这个符号 : MyClassName<String> in Java mean? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15154769/