Why collection literals?

前端 未结 11 881
无人及你
无人及你 2020-12-29 04:09

From the various online articles on Java 7 I have come to know that Java 7 will be having collection literals1 like the following:

List

        
11条回答
  •  鱼传尺愫
    2020-12-29 04:50

    They might have been inspired by the declarative programming style of JavaFX. If that is the case however, I'm disappointed that they didn't go all the way to support object literals as well. Here's an example of object literals in JavaFX:

    Stage {
        title: "Group-Nodes-Transformation"
        scene: Scene {
            width: 600
            height: 600
            content: Group {
                content: [
                    Circle {
                        centerX: 300
                        centerY: 300
                        radius: 250
                        fill: Color.WHITE
                        stroke: Color.BLACK
                    },
                    Text {
                        x: 300
                        y: 300
                        content: "Mr. Duke"
                    },
                    ImageView {
                        image: Image {
                            url: "D:\\TEST\\Documents\\duke.png"
                            width:50
                            height:50
                        }
                    }
                ]
            }
        }
    }
    

    I think that this style of programming certainly lends itself to certain application areas. In the end it's always a matter of taste...

提交回复
热议问题