Is there a functionality in Java similar to C#'s anonymous types?

后端 未结 3 1852
星月不相逢
星月不相逢 2021-02-19 21:58

I was wondering if there exists a similar functionality in Java similar to C#\'s anonymous types:

var a = new {Count = 5, Message = \"A string.\"};

3条回答
  •  粉色の甜心
    2021-02-19 22:16

    No. There is no equivalent. There is no typeless variable declaration (var) in Java that the Java compiler could fill in with the auto-generated type name to allow a.Count and a.Message to be accessed.

提交回复
热议问题