gpt4 book ai didi

java - 在类中设置变量

转载 作者:行者123 更新时间:2023-12-01 12:47:36 26 4
gpt4 key购买 nike

我对 Java 相当陌生,很难理解如何访问 Bean 类中的方法并将变量设置为特定值。我正在创建 Bean 类的新实例,并希望将变量设置为特定值。我还想将这些全部存储在一个列表中。这是我的代码: 公共(public)类ReportBean{ //实例变量

private String inventoryFulfillmentSpecialist;
private String inventoryFulfillmentManager;
private String poNumber;
private String poReferenceNumber;
private String shipToLoc;
private String poStatus;
private String importStatus;
private String orderType;
private String item;
private String mismatchFields;
private String tValue;
private String hValue;

/**
* Getter method for variable 'inventoryFulfillmentSpecialist'.
* @return String
*/
public String getInventoryFulfillmentManager() {
return inventoryFulfillmentManager;
}
/**
* Getter method for variable 'inventoryFulfillmentSpecialist'.
* @return String
*/
public String getInventoryFulfillmentSpecialist() {
return inventoryFulfillmentSpecialist;
}
/**
* Getter method for variable 'poNumber'.
* @return String
*/
public String getPoNumber() {
return poNumber;
}
/**
* Getter method for variable 'poReferenceNumber'.
* @return String
*/
public String getPoReferenceNumber() {
return poReferenceNumber;
}
/**
* Getter method for variable 'shipToLoc'.
* @return String
*/
public String getShipToLoc() {
return shipToLoc;
}
/**
* Getter method for variable 'poStatus'.
* @return String
*/
public String getPoStatus() {
return poStatus;
}
/**
* Getter method for variable 'importStatus'.
* @return String
*/
public String getImportStatus() {
return importStatus;
}
/**
* Getter method for variable 'orderType'.
* @return String
*/
public String getOrderType() {
return orderType;
}
/**
* Getter method for variable 'item'.
* @return String
*/
public String getItem() {
return item;
}
/**
* Getter method for variable 'tssVsPoMisMatchFields'.
* @return String
*/
public String getTssVsPODirectMisMatchFields() {
return tssVsPODirectMisMatchFields;
}
/**
* Getter method for variable 'tradeStoneValue'.
* @return String
*/
public String getTradeStoneValue() {
return tradeStoneValue;
}
/**
* Getter method for variable 'hostValue'.
* @return String
*/
public String getHostValue() {
return hostValue;
}
/**
* Setter method for variable 'inventoryFullfilmentManager'.
* @param inventoryFulfillmentManager String
*/
public void setInventoryFulfillmentManager(String inventoryFulfillmentManager) {
this.inventoryFulfillmentManager = inventoryFulfillmentManager;
}
/**
* Setter method for variable 'inventoryFulfillmentSpecialist'.
* @param inventoryFulfillmentSpecialist String
*/
public void setInventoryFulfillmentSpecialist(
String inventoryFulfillmentSpecialist) {
this.inventoryFulfillmentSpecialist = inventoryFulfillmentSpecialist;
}
/**
* Setter method for variable 'poNumber'.
* @param poNumber String
*/
public void setPoNumber(String poNumber) {
this.poNumber = poNumber;
}
/**
* Setter method for variable 'poReferenceNumber'.
* @param poReferenceNumber String
*/
public void setPoReferenceNumber(String poReferenceNumber) {
this.poReferenceNumber = poReferenceNumber;
}
/**
* Setter method for variable 'shipToLoc'.
* @param shipToLoc String
*/
public void setShipToLoc(String shipToLoc) {
this.shipToLoc = shipToLoc;
}
/**
* Setter method for variable 'poStatus'.
* @param poStatus String
*/
public void setPoStatus(String poStatus) {
this.poStatus = poStatus;
}
/**
* Setter method for variable 'importStatus'.
* @param importStatus String
*/
public void setImportStatus(String importStatus) {
this.importStatus = importStatus;
}
/**
* Setter method for variable 'orderType'.
* @param orderType String
*/
public void setOrderType(String orderType) {
this.orderType = orderType;
}
/**
* Setter method for variable 'item'.
* @param item String
*/
public void setItem(String item) {
this.item = item;
}
/**
* Setter method for variable 'tssVsPODirectMisMatchFields'.
* @param tssVsPODirectMisMatchFields String
*/
public void setTssVsPODirectMisMatchFields(String tssVsPODirectMisMatchFields) {
this.tssVsPODirectMisMatchFields = tssVsPODirectMisMatchFields;
}
/**
* Setter method for variable 'tradeStoneValue'.
* @param tradeStoneValue String
*/
public void setTradeStoneValue(String tradeStoneValue) {
this.tradeStoneValue = tradeStoneValue;
}
/**
* Setter method for variable 'hostValue'.
* @param hostValue String
*/
public void setHostValue(String hostValue) {
this.hostValue = hostValue;
}

List<ReportBean> reportData = new ArrayList<ReportBean>();
ReportBean bean1 = new ReportBean();
ReportBean bean2 = new ReportBean();
ReportBean bean3 = new ReportBean();
bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700");

public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ReportBean: ");
sb.append("inventoryFulfillmentManager = " + getInventoryFulfillmentManager() + " ");
sb.append("inventoryFulfillmentSpecialist = " + getInventoryFulfillmentSpecialist() + " ");
sb.append("poNumber = " + getPoNumber() + " ");
sb.append("poReferenceNumber = " + getPoReferenceNumber() + " ");
sb.append("shipToLoc = " + getShipToLoc() + " ");
sb.append("poStatus = " + getPoStatus() + " ");
sb.append("importStatus = " + getImportStatus() + " ");
sb.append("orderType = + " + getOrderType() + " ");
sb.append("item = " + getItem() + " ");
sb.append("tssVsPODirectMisMatchFields = " + getTssVsPODirectMisMatchFields() + " ");
sb.append("tradeStoneValue = " + getTradeStoneValue() + " ");
sb.append("hostValue = " + getHostValue() + " ");

return sb.toString();
}

}

我收到错误,当我尝试说 bean1.setxxxx 时,我收到红色波浪线,上面写着“ token 上的语法错误,错误的构造”。如果有人可以提供帮助,我们将不胜感激,谢谢。

最佳答案

bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700");

这部分代码只是 float 在您的类中。这是一个结构化编程的事情。在 Java 中,所有代码都必须位于方法或函数内。

您必须使用静态 main 方法来封装它:

public static void main(String[] args) {
//yourcode here
}

关于java - 在类中设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com