例如帮String类型扩展一个ToInt()方法
String
ToInt()
光阴似箭催人老,日月如移越少年。
String class is special... Others can be inherited and then added methods
No. Java的类是死的, 一但写好就不再有更改能力. 你应该不是问, 通过继承来添加新的方法. 如果有的话, Scala也不用费劲搞个隐式视图To add methods to existing classes.
Java
Scala
隐式视图
Well, this is not solid evidence either.
Are you talking about the interface?
No. Scala and PHP have trait.
trait
Java doesn’t even have the ability to alias classes.
Decorator mode.
String class is special... Others can be inherited and then added methods
No.
Java
的类是死的, 一但写好就不再有更改能力. 你应该不是问, 通过继承来添加新的方法. 如果有的话,Scala
也不用费劲搞个隐式视图
To add methods to existing classes.Well, this is not solid evidence either.
Are you talking about the interface?
No. Scala and PHP have
trait
.Java doesn’t even have the ability to alias classes.
Decorator mode.