开发者

what does this code snippet mean

code snippet:

  for( String token : tokens ) 
     开发者_JAVA技巧   {
            try
            {
                Url url = as("mycompany", "someapikey").call(shorten(token));
             }
         } 

what do the 'as' and the 'call' mean. Are they keywords in java?

i was browsing and i found this code and i would like to understand what it means.

thank you in advance.


Looks like it's using the bit.ly library to shorten URLs. the for loop is iterating through strings in a collection, tokens. it then creates a shortened URL via the bit.ly library. These aren't keywords in Java, they are just method names.

android bit.ly library: http://code.google.com/p/bitlyj/


No, they are regular methods. The as() method should be in the class this is from (or a superclass), while the call() method is defined for the type returned by as().

It would be helpful to have a link back to the original source where you found this, as more context is often useful.


as and call are not keywords in Java.

It seems that as(String s1, String s2) is a method that returns an object that has a method call(..).

That method call(..) is invoked on the return value of as(..).


Maybe a static import?

For example, if class Foo has a static method as(), you can use

import static Foo.as;

{
  //now can do this:
  as();  //equal to Foo.as();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜