【发布时间】:2015-04-22 09:31:50
【问题描述】:
我有一个关于 oop 的问题。它可能看起来真的微不足道。我在网上看到过他们使用this 访问私有方法的示例。真的有必要吗?是特定语言的吗?
这是一个可以使用this 或使用this 的示例。
class A {
def test(): String = {
val x = this.test_2()
x
}
private def test_2(): String = {
"This is working"
}
}
object Main extends App {
val a = new A
val x = a.test
println(x)
}
这里没有this的相同代码。两者都在工作。
class A {
def test(): String = {
val x = test_2()
x
}
private def test_2(): String = {
"This is working"
}
}
object Main extends App {
val a = new A
val x = a.test
println(x)
}
【问题讨论】:
标签: oop methods this private private-methods