search

Home  >  Q&A  >  body text

Java有没有C#那样可以对某个类进行扩展,添加新的方法

例如帮String类型扩展一个ToInt()方法

大家讲道理大家讲道理2894 days ago405

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:17:39

    String class is special... Others can be inherited and then added methods

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:17:39

    No. Java的类是死的, 一但写好就不再有更改能力. 你应该不是问, 通过继承来添加新的方法. 如果有的话, Scala也不用费劲搞个隐式视图To add methods to existing classes.

    Well, this is not solid evidence either.

    reply
    0
  • 阿神

    阿神2017-04-18 09:17:39

    Are you talking about the interface?

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:17:39

    No. Scala and PHP have trait.

    Java doesn’t even have the ability to alias classes.

    reply
    0
  • 阿神

    阿神2017-04-18 09:17:39

    Decorator mode.

    reply
    0
  • Cancelreply