문제

I'm quite new to Java.

My general question: how do I find out what package contains a particular method.

I want to use a method from an external library. Looking at the JavaDocs, it exists, and is here (http://twitter4j.org/javadoc/index.html).

However, I need to know how I can use that method. What should I import, and how can I use that method.

import twitter4j.this.package

maybe.something.before
    .getMentionsTimeline()
        .now.I.can.use.this

I looked for the longest time, but I'm still having trouble understanding the JavaDocs. Could someone clarify a general rule?

도움이 되었습니까?

해결책

So say you want to use a method in ArrayList, such as size(), but you don't know what package to import.

The first step is to go to the javadoc for the class containing the method you want. Here's the ArrayList online Javadoc:

enter image description here

See the little "java.util" above the big header with the class name? That's the package you'll need to import. Or more specifically, that's the prefix to the class you need to import. So in this case you'll import java.util.ArrayList.

Now, how you use the method depends on if it's an instance method or a static method. If it's an instance method you'll have to instantiate the class in question and call the method on the instance:

ClassName varName = new ClassName(possibleParameters);
varName.methodName(possibleParameters);

If it's a static method you can use it qualifying the method with the class name:

ClassName.StaticMethod(possibleParameters);

다른 팁

View the Javadoc for getMentionsTimeline(). It is a method in an interface, so to call it you will need an object whose class implements the interface. Depending on how you obtain and reference the object, you may need to import its class and/or the interface, twitter4j.api.TimelinesResources.

The only known implementing class is TwitterImpl.

The package of a class appears at the top left of its Javadoc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top