Created by Wang, Jerry on Oct 08, 2015
看个Scala的例子:
package method
/**
* @author I042416
*/
class booleaMethod {
private var firstName = ""
private var lastName = ""
def this(first: String, last: String) { // this is an Auxiliary constructor
this() // call primary constructor
this.firstName = first
this.lastName = last
}
def printArgs(args: Array[String]): Integer = {
args.foreach(println)
return args.length
}
def getName( bGetfullName: Boolean): String = {
if( bGetfullName) {
this.firstName + " " + this.lastName
}
else{
this.firstName
}
}
}
object testBoolean extends App {
val booleanMethod = new booleaMethod("Jerry", "Wang")
println(booleanMethod.getName(bGetfullName = false))
println(booleanMethod.getName(bGetfullName = true))
}
产生一个内部类:
外部类通过参数$outer传到内部类里
要获取更多Jerry的原创文章,请关注公众号"汪子熙":