伪造的受保护变量
使用setget关键字的强大功能,您可以保护您的变量不被用于创建变量的类之外。
extends Nodeclass_name Animalsvar _protectedVar:String = "Protected Variable" setget protectedSet, protectedGetfunc protectedSet(param1):print('Can\'t Access Private Variable Setter')func protectedGet():print('Can\'t Access Private Variable Getter')
通过创建既不更改变量值也不返回其值的 setter 和 getter 方法,您将创建一个其他类无法访问其值的变量。
