Why will there be no native properties in Java 7?

后端 未结 5 1796
陌清茗
陌清茗 2021-02-18 21:57

Is there any rational reason, why native properties will not be part of Java 7?

相关标签:
5条回答
  • 2021-02-18 22:15
    • Not enough time?
    • Not yet specced properly?
    • Difficult to add to java due to java's implementation?
    • Deemed not important enough, ie other things were prioritiesed?
    0 讨论(0)
  • 2021-02-18 22:19

    There are some high-level reasons related to schedule and resources of course. Implementation of properties and understanding all of the ramifications and intersections with other language features is a large task similar to the size of various Java 5 language changes.

    But I think the real reason Sun is not pushing properties is the same as closures:

    1) There is no consensus on what the implementation should look like. Or rather, there are many competing alternatives and people who are passionate about properties disagree about crucial parts of the implementation.

    2) Perhaps more importantly, there is a significant lack of consensus about whether the feature is wanted at all. While many people want properties, there are also many people that don't think it's necessary or useful (in particular, I think server-side people see properties as far less crucial to their daily life than swing programmers).

    Properties history here:

    • http://tech.puredanger.com/java7#property
    0 讨论(0)
  • 2021-02-18 22:27

    Doing properties "right" in Java will not be easy. Rémi Forax's work especially has been valuable in figuring out what this might look like, and uncovering a lot of the "gotchas" that will have to be dealt with.

    Meanwhile, Java 7 has already taken too long. The closures debate was a huge, controversial distraction that wasted a lot of mind-power that could have been used to develop features (like properties) that have broad consensus of support. Eventually, the decision was made to limit major changes to modularization (Project Jigsaw). Only "small change" is being considered for the language (under Project Coin).

    JavaFX has beautiful property support, so Sun clearly understands the value of properties and knows how to implement them. But having been spoiled by JavaFX properties, developers are less likely to settle for a half-baked implementation in Java. If they are worth doing, they are worth doing right.

    0 讨论(0)
  • 2021-02-18 22:32

    Any given thing is "not done" by default, so no particular reason is needed for something to remain not done. Rather some compelling reason is needed to move something from "not done" to "planned" or "done". No sufficiently compelling reason has yet arisen for this language feature.

    0 讨论(0)
  • 2021-02-18 22:34

    There are two more reasons to avoid properties in any language:

    • Properties are not very object-oriented. Making them easy to write encourages the pattern where the object just serves up its internal state and the caller manipulates it. The object should provide higher-level methods and keep its internals private. Next time you're tediously implementing a getter, consider what the caller will do with the data and whether you can just provide that functionality directly.

    • Properties encourage mutable state (through setters), which makes a program less parallelizable. As the number of cores goes up, we should all be trying to make our objects immutable to make concurrent reasoning easier. Next time you're tediously implementing a setter, consider removing it and making the object immutable.

    0 讨论(0)
提交回复
热议问题