如何获取 Argument 的值来实现这样的方法。 argument.nameOfTheMethod()
。
我想在这个参数上使用一个条件来编写这个方法的代码。
例如:
"foo".charAt()
charAt
如何访问"foo"
的值?
最佳答案
"foo".CharAt()
How doescharAt
access the value of"foo"
?
charAt
通过方法内部的 this
引用访问值 "foo"
。
调用 obj.method()
时,您可以将 obj
视为名称为 this
的隐式参数。在 Java 8 中,您甚至可以在方法签名中将其显式化,如下所示:
class SomeClass {
public void someMethod(SomeClass this) {
// ...
}
}
这是一个很好的起点:The Java™ Tutorials: Using the this
Keyword .
关于java - 如何获取 argument.nameOfTheMethod() 中参数的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28899627/