I just try to understand some code of an api, by reading the source. Here is a link:
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/configuration/MemorySection.java
In this class you can find the method public int getInt(String path, int def). This method calls toInt(val). Where can I find this method. As there is no object or class specified such as anObject.toInt(val) or ClassName.toInt(val) the method must be defined in that class or in a superclass, but I cant find it.
My questions: Is that the original source? Can you find it? Where is it?
The toInt() method comes from the class org.bukkit.util.NumberConversions.
Now, why isn't the class specified and how can this work ? If you look at the imports at the top of the file, you will see this :
import static org.bukkit.util.NumberConversions.*;
This basically means
Make available to me any public static method in in the
org.bukkit.util.NumberConversionsclass.
This is a useful feature of Java when you want to make your code more concise. However, since the class responsible for this method is not immediately obvious, it is better to use it only for widely-user helper methods, such as toInt here.
Another typical example are the JUnit assertions. It is even explained in their javadoc :
These methods can be used directly: Assert.assertEquals(...), however, they read better if they are referenced through static import:
import static org.junit.Assert.*; ... assertEquals(...);
You can find an import statement with static in the first line of the java file(which is nothing but the static import, imports only the methods of the class).
import static org.bukkit.util.NumberConversions.*;
You can find the method in this link. Just traverse to the class and search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With