方法不可用

发布于 2024-10-28 08:13:59 字数 449 浏览 3 评论 0原文

有一个 CustomerData 类,其中包含各种字段以及这些字段的 set/get 方法。

class CustomerData{

 int ssn;
 int homePhone; 
 int officePhone;
 String product;
 String sameAsPrev=null;
 // set/get methods
}

我需要用客户类替换此类。客户类位于 jar 文件中。因此我无法修改。 CustomerData 的某些字段在 Customer 类中不可用,我需要在 Customer 对象上调用这些字段。

有一个限制,我不能添加任何类,只能用 Customer 替换 CustomerData 类。

在控制器中调用字段上的 set 方法后,他们使用映射来存储数据。

我怎样才能获得这些字段的值。

请给一些建议...

There is a class CustomerData which contains various fields and set/get method for those fields.

class CustomerData{

 int ssn;
 int homePhone; 
 int officePhone;
 String product;
 String sameAsPrev=null;
 // set/get methods
}

I need to replace this class with class Customer. Customer class is in jar file. hence i can't modified. some fields of CustomerData is not available in Customer class and i need to call those fields on Customer Object.

there is a restriction that i can't add any class but just to replace CustomerData class with Customer.

in Controller after calling set methods on field they used map to store the data.

how can i get the values of those fields.

please give some suggestions...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜司空 2024-11-04 08:13:59

如果您的类中但不在 Customer 类中的字段是必填字段,那么您有两个选择:
选项 1(isa,扩展)
用您的类扩展客户类。

public class CustomerDescendant
extends Customer
{
  ... stuff goes here
}

选项 2(hasa、包含):
将 Customer 类包含在您的类中。

public class CustomerWrapper
{
  private Customer customerInstance;

  ... stuff

  getFieldInCustomerClass()
  {
    return customerInstance.getFieldInQuestion();
  }

  ... stuff
}

选项 3(奖励选项):
创建一个类,其中包含所需的字段,但这些字段不在 Customer 类中。


public class FieldsNotInCustomerClass
{
  ... all fields that are not in the customer class, but which are required.
}

If the fields that are in your class but, which are not in the Customer class are mandatory, then you have two options:
Option 1 (isa, extends)
Extend the Customer class with your class.

public class CustomerDescendant
extends Customer
{
  ... stuff goes here
}

Option 2 (hasa, contains):
Contain the Customer class in your class.

public class CustomerWrapper
{
  private Customer customerInstance;

  ... stuff

  getFieldInCustomerClass()
  {
    return customerInstance.getFieldInQuestion();
  }

  ... stuff
}

Option 3 (bonus option):
Create a class with the fields that are required but, which are not in the Customer class.


public class FieldsNotInCustomerClass
{
  ... all fields that are not in the customer class, but which are required.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文