Skip to content

Instantly share code, notes, and snippets.

@lu911
Last active December 20, 2015 10:19
Show Gist options
  • Save lu911/6114700 to your computer and use it in GitHub Desktop.
Save lu911/6114700 to your computer and use it in GitHub Desktop.
Scala Property
package org.sunrin
import scala.beans.BeanProperty
class Property
{
var varProperty = "var"
val valProperty = "val"
private var privateVarProperty = "private_var"
// private val private_var_property = "private_val" => error
def getPrivateVarProperty = {
this.privateVarProperty
}
def setPrivateVarProperty(property: String): Unit = {
this.privateVarProperty = property;
}
@BeanProperty var beanVarProperty = "bean_var_property"
@BeanProperty val beanValProperty = "bean_val_property"
}
object HelloWorld
{
def main(args: Array[String]): Unit = {
val property = new Property()
println(property.varProperty)
println(property.valProperty)
property.varProperty="var change"
// property.valProperty="val change" => error
println(property.varProperty)
println(property.valProperty)
println(property.getPrivateVarProperty);
property.setPrivateVarProperty("private_var change")
println(property.getPrivateVarProperty);
println(property.beanVarProperty)
println(property.beanValProperty)
property.beanVarProperty = "bean_var_property change"
println(property.beanVarProperty)
property setBeanVarProperty "bean_var_property change 2"
println(property.getBeanVarProperty)
println(property.getBeanValProperty)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment