[英]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.