簡體   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