简体   繁体   English

有没有办法可以使用该类的现有实例(对象)

[英]Is there a way i can use the existing instance (object) of the class

I have a class implemented as below我有一个类实现如下

@Builder
class A extends B {

   @Getter
   public List<Customer> cusromers = new ArrayList<>();

   @Override
   public void add(){
     c.add(obj);
   }

}

Below is in different project以下是在不同的项目中

class C {
    public Student<T, C> getValues() {
        return A.builder().customers(getCustomers()).build()
    }
}

The below is different project and has dependency of the above's project以下是不同的项目,并且具有上述项目的依赖关系

@Test
class Test {
   // I need to check the instance of class A and test if the instance has added some modifications for the list above stated class
}

Please any one help me on this.请任何人帮助我。 Excuse me if i do any mistake对不起,如果我做错了什么

You probably need some @Getter and @Setter annotation in combination with your @Builder .您可能需要将一些@Getter@Setter注释与您的@Builder结合使用。

@Getter
@Setter
@Builder
class A extends B {

   public List<Customer> customers = new ArrayList<>();

   @Override
   public void add(){
     customers.add(new Customer());
   }

}

@Test
class Test {
    A a = new A():
    List<Customer> customers = a.getCustomers();
    assertEquals(1, customers.size());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法检查一个类是否有一个方法,然后在已经存在的对象实例上调用它? - Is there a way to check if a class has a method and then invoke it on an already existing instance of the object? 有什么办法可以在不同的类中使用 Scanner 对象吗? - Is there any way I can use a Scanner object in a different class? 如果将类用作类型参数,如何在参数化的类中创建此对象的实例? - If I use a class as a type parameter, how can I create an instance of this object within the parameterized class? 我可以覆盖类对象的新实例吗? - Can I override a new instance of a class object? 如何在SftpProgressMonitor实例中使用现有的JProgressBar? - How can I use existing JProgressBar in SftpProgressMonitor instance? 如何使用由其他类创建的类的实例? - How can I use an instance of a class that was created by a different class? 如何获取在类中确定的对象的实例 - How can I get the instance of an object that is determined in the class 我可以在 3 个或更多班级使用一个对象吗? - Can I use One object at 3 or more class? 如何将类对象用于其他对象? - How can I use a class object into other? 我在哪里可以在Java中使用类方法和实例方法 - Where can i use class methods and instance methods in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM