java 显式参数隐式参数_Java中的隐式参数

java 显式参数隐式参数

The implicit parameter in Java is the object that the method belongs to. It's passed by specifying the reference or variable of the object before the name of the method. An implicit parameter is opposite to an explicit parameter, which is passed when specifying the parameter in the parenthesis of a method call. If a parameter isn't explicitly defined, the parameter is considered implicit.

Java中的隐式参数是该方法所属的对象。 通过在方法名称之前指定对象的引用或变量来传递它。 隐式参数是相反的明确 参数 ,它规定在一个方法调用的括号中的参数时被传递。 如果未明确定义参数,则该参数被认为是隐式的。

显式方法示例 ( Explicit Method Example )

When your program calls a method of an object, it's common to pass a value to the method. For example, here, the object Employee has a method called setJobTitle:

当程序调用对象的方法时,通常将值传递给该方法。 例如,在这里,对象Employee有一个名为setJobTitle的方法:


Employee dave = new Employee(); dave.setJobTitle("Candlest

The String "Candlestick Maker" is an explicit parameter being passed to the setJobTitle method.

字符串“ Candlestick Maker”是一个显式参数,将传递给setJobTitle方法。

隐式方法示例 ( Implicit Method Example )

However, there is another parameter in the method call that is known as the implicit parameter. The implicit parameter is the object the method belongs to. In the above example, it's dave, the object of type Employee.

但是,方法调用中还有另一个参数,称为隐式参数。 隐式参数是该方法所属的对象。 在上面的示例中,它是dave ,即Employee类型的对象。

Implicit parameters are not defined within a method declaration because they are implied by the class the method is in:

隐式参数未在方法声明中定义,因为方法所在的类隐含了它们:


public class Employee {  public void setJobTitle(String jobTitle)  {    this.jobTitle =

In order to call the setJobTitle method, there must be an object of type Employee.

为了调用setJobTitle方法,必须有一个类型为Employee的对象。

翻译自: https://www.thoughtco.com/implicit-parameter-2034139

java 显式参数隐式参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值