开发者

Is "set" a keyword for Java?

开发者 https://www.devze.com 2023-04-03 14:33 出处:网络
Beginner on Java, I got this piece of code from .java file from a big project which compiles for (Var var : cfg.getArgs())

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,

  • 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.


set is likely the name of another method in the Java code you borrowed.


According to this list, no set isn't a keyword:

0

精彩评论

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