Is the `new` keyword in java redundant?

后端 未结 5 1469
闹比i
闹比i 2020-11-29 05:29

I am coming from C++ so there is one feature of java that I don\'t quite understand. I have read that all objects must be created using the keyword new, with th

5条回答
  •  悲哀的现实
    2020-11-29 05:59

    If you came from C++, why are you surprised? Doesn't C++ have the same new, for the same purpose? Java tries to follow most of C/C++ syntax, that's most likely the reason.

    Commenting on artbristol's answer: It is highly improbable that Java designers laid out namespaces first, then were forced to add new keyword. It is very likely the opposite: new was there first, then they found that it allows them to have constructor names collide with other names.

提交回复
热议问题