Is there a difference between explicitly putting the type into the diamond operator vs letting java figure it out?

前端 未结 4 1761
终归单人心
终归单人心 2020-12-11 18:51

Is there any difference between initialization via:

MyWrapper wrapper = new MyWrapper();

vs initialization via:

4条回答
  •  悲&欢浪女
    2020-12-11 19:52

    JDK 7 allows to not redefine this "redundant" diamond at initialization time.

    It's just a shorter syntax.

    With JDK <= JDK 6, the latter doesn't work, you have to use the former.

提交回复
热议问题