开发者

function calls between classes

开发者 https://www.devze.com 2023-02-03 15:23 出处:网络
Can anyone please tell me what r we actually meaning by the following statement (I encountered it in one of my tutorials)

Can anyone please tell me what r we actually meaning by the following statement (I encountered it in one of my tutorials)

String s1 = Utilities.gets1(UtilityConstants.MY_SEVICE_NA开发者_StackOverflow中文版ME);

I have found that Utilities.java , UtilityConstants.java files do exist in the project.

I know with this vague little information it is difficult for you to convey the proper meaning.

But can you please make clear what sort of call is that?


There exists a method gets1 in Utilities class, which accepts a String parameter and returns a String. The string parameter happens to be selected from another class UtilityConstants, which contains at least one static [which could also be final] string variable declaration having the name MY_SEVICE_NAME.


Well it certainly looks like a call to a static method called gets1 in the Utilities class, with an argument of UtilityConstants.MY_SERVICE_NAME.

In other words, the expression UtilityConstanst.MY_SERVICE_NAME is evaluated, and then that value is passed as an argument to gets1, where the corresponding parameter will start off with that value.

The return value of the method is a String reference - which could conceivably be a null reference. The value of s1 will be the returned value. (Note that it's a reference, not a String object itself.)

If it is a static method (as opposed to the possible-but-unlikely situation where Utilities is an expression such as a variable), then no instance of the Utilities class is required to make the call; the gets1 method won't have an implicit instance of Utilities to access.

Is that what you were looking for?


From the Utilities class you are taking the name of a service identified by the static (and possibly final) field MY_SEVICE_NAME.

I said possibly because the field name is uppercase and _ separated, this in java usually means that you are dealing with a final field.


MY_SEVICE_NAME is static constant of UtilityConstants

gets1 is static method of Utilities class

you can read about static here - http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html

In nutshell - static is not an instance variable/constant, it is a variable/constant of the class, you can always access it without class instance.

0

精彩评论

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