Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "set" a keyword for Java?

Tags:

java

keyword

set

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?

like image 708
zell Avatar asked Jun 11 '26 05:06

zell


1 Answers

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,

  • Java Language Keywords


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.

like image 143
aioobe Avatar answered Jun 13 '26 18:06

aioobe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!