简体   繁体   中英

How to reference a variable of Domain class in my method

I want to check if a boolean variable from a Domain class equates to true in my method.

private Boolean exampleName1 = null;

This is in a @Entity class called Javaclass1.java

My method is in JavaClass2.java

public static String myMethod(name1, nameClass){
   if(nameClass != null){
       return name1;
  }
}

I want to execute the if condition above only if the boolean for exampleName1 in the entity class is true. It has a getter and setter. How would I import and setup the if condition?

If you want to read a private attribute from another entity (in your example something like getExampleName1() ) you should have instance of that entity at first. you should import your entity by Name and then call the getter name. for example:

public static String myMethod(String name1, String nameClass, Javaclass1 javaClass1){
   if(nameClass != null && javaClass1.getExampleName1 == true ){
       return name1;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM