java - 在类中设置变量

标签 java list static

我对 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/

相关文章:

java - 我怎样才能让firebase短链接脱离任务

python - 列表列表中的排列

c# - 为什么运算符方法在 C# 中应该是静态的?

c# - 按两个标准 C# 对列表进行分组

php - 在PHP中,动态调用静态方法时使用forward_static_call_array()而不是call_user_func_array()有什么优点吗?

java - 什么是静态变量

java - 使用 Eclipse 升级注释处理器代码 (Java) 时出现问题

java - Spring MVC;避免 url 中的文件扩展名?

Java Eclipse 求值表达式

python - 将列表 append 到列表,覆盖值