Beginner on Java, I got this piece of code from .java file from a big project which compiles
for (Var var : cfg.getArgs())
set(var);
but in my Java program there is no definition of that set method. I am just wondering whether set is a keyword of Java?
No, set is not a keyword in Java.
Member function
What you see in that snippet is a call to a method called set. Presumably a member method of the enclosing class, in which case it is identical to the more familiar syntax:
this.set(var);
Look above or below that particular snippet, and you'll most likely find the definition. It should look something like
public void set(Var var) {
....
}
Member function of super class
Note that it can also be a method of a super class. I.e., if the class is declared as
class Configuration extends SomeClass { ...
then the definition of the set method could be in SomeClass.
Here is the official list of keywords btw,
Statically imported method
If it's not defined in the class, and you can't for your life find it in any super class, then it may be a statically imported method from some other class. In that case, look for something like
static import org.comp.Class.set;
in the top of the .java file.
Finally, if you're using Eclipse to develop, you can hit F4 or right click on the identifier and select declarations in project to jump to the definition of the method.
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