繁体   English   中英

Java 中的 C# object 变量的等价物是什么?

[英]What is the equivalent of a C# object variable in Java?

我有这个 C# 代码:

var invoice = new {
       code = "01",
       otherThings = "etc",
       ...
  }

Java 中的等效项是什么?

我尝试创建一个: Object[] invoice = new Object[]{}但不知道如何填写 object。

我希望我足够清楚,谢谢。

你可以这样写:

Invoice i = new Invoice(){...};

但这不是干净的代码。

只需编写一个具有所有属性的构造函数,例如:

public invoice(String code, String otherThings)
{
     this.code = code;
     this.otherThings = otherThings;
}

...

Invoice i = new Invoice("asdfasdf", "asdfasdf");

Oject[] invoice = new Object[5];
invoice[0] = (Object)i;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM