Is correct to assign to a variable using && with the same variable in Java?

assigning values to variables in java
how to assign a value to a variable in python
assigning values to variables in c programming
what does it mean to assign a value to a variable
what is the first step in assigning a variable value?
assigning values to variables in javascript
declare variable in html
java variable assignment

I'm making some changes into an old code than requires maintenance, and I found something like this

public boolean aMethod(){
    boolean isValid = true;

    **isValid = isValid &&** executeGetDocs(id.toString(),program().toString(), document.get(name));

  return isValid;
}

The method executeGetDocs may return true or false.

But I'm not sure if: **isValid = isValid && executeGetDocs ** is correct or is just redundant.

So here I am, can anyone please, give me some explanation about this?

Thanks a lot!

EDITED

Whole method:

private boolean validateDocs(List<Map<String, Object>> documentsList) {
        boolean isValid = true;
        StringBuilder gradoAntComp = new StringBuilder();
        for (Map<String, Object> document : documentsList) {
            String id = document.get("ID_DOC").toString();
            if (id.equalsIgnoreCase("25")) {
                isValid = getData(id.toString(),program().toString(), document.get(name))
            } else if (id.equalsIgnoreCase("26") ) {
                isValid = isValid && getDocs(id.toString(),program().toString(), document.get(name));
            } 
        }
        return isValid;
    }

It was redundant in your original question. The original method you posted could be reduced to:

public boolean aMethod() {
    return executeGetDocs(id.toString(),program().toString(), document.get(name));
}

since (true && x) == x for any boolean x.

However, since you changed the question, the answer changes as well. Now the boolean variable may change multiple times within a loop. Therefore it makes sense to AND the previous value of the variable (which may be true or false) with another boolean, which might cause its value to change.

private boolean validateDocs(List<Map<String, Object>> documentsList) {
    boolean isValid = true;
    StringBuilder gradoAntComp = new StringBuilder();
    for (Map<String, Object> document : documentsList) {
        String id = document.get("ID_DOC").toString();
        if (id.equalsIgnoreCase("25")) {
            // this can set isValid to either false or true
            isValid = getData(id.toString(),program().toString(), document.get(name))
        } else if (id.equalsIgnoreCase("26") ) {
            // therefore performing logical AND between the previous value of
            // isValid and some additional boolean is meaningful - isValid will
            // be assigned true only if it was true before this statement AND
            // getDocs(id.toString(),program().toString(), document.get(name)) is true
            isValid = isValid && getDocs(id.toString(),program().toString(), document.get(name));
        } 
    }
    return isValid;
}

"Assign a variable to a value" or the other way round?, Assign a value to a variable is correct. The confusion may arise from the fact that you can correctly say assign a variable a value, which has  Use cases; Stack Overflow Public questions and answers; Teams Private questions and answers for your team; Enterprise Private self-hosted questions and answers for


Not that we see your entire method, we can see that you're attempting to assign to isValid within a loop. Written this way, the code is using the && conditional-and operator to only execute the method getDocs if isValid is still true.

If a previous assignment to isValid set it to false, then getDocs won't even be called; it will be short-circuited. This means that the && operator already knows that the result of the expression will be false, because isValid is false, so it "short-circuits" the evaluation and doesn't evaluate the other operand -- the call to getDocs.

This makes a lot of sense especially if getDocs is a method with a large overhead cost.

Variable assignment - assign values to variables, Variables are explicitly set with an assignment statement. The variable on the left is set to the list of values on the right. The right-side values are either literals  First of all, ReSharper is actually correct. It isn't a type, it's a variable. Granted, it's a variable that is holding the reflection object that corresponds to a type, but that isn't enough. Between the <> brackets, you have to write the name of a type, not the name of any other identifier.


As you initialize isValid as true it's useless you can rewrite it as:

public boolean aMethod(){
    return executeGetDocs(id.toString(),program().toString(), document.get(name));
}

Assignment (computer science), In this case, the value is declared implicitly; to explicitly declare a variable, use the command var before a variable name. Consider the following example: <​script  New Mathematica user here. I'm using some code from a colleague and editing it to give me more specific results in finding the zeros of a complex polynomial. I am attempting to find a way to assign a value to a variable A symbolically - i.e., give variable A an expression value that depends on other variables.


Assigning values to variables, This guide shows you the basics of creation and use of variables in infers the value type by parsing the right-hand part of the assignment and  I'm using Excel 2003. I start by selecting manually a range in one worksheet and want to pick up data cell by cell to process and place into another worksheet. The data manipulation and putting into the target cells is straightforward. I want to store the user's initial selection of cells in a range variable.


Python Variables and Assignment, Variables in a computer program are analogous to "Buckets" or "Envelopes" where where it is always true that if given two positive numbers (lets use the symbols 'a' We "put" information into a variable using the assignment operator, e.g.,  To assign a value to a variable, use '='. To compare values for equality, use '=='." I already followed instruction above but another happened ERROR 2: Illegal use of reserved keyword "for".


Programming - Variables, It is also very important that the value assigned is of the correct type. The most common form of statement in a program uses the assignment operator, =, and  I need to assign it out as follows: v1 = vQty. v2 = vItem. v3 = vCost. v4 = vDate . Using the variable assignment command, it does not look like I can do this. Putting this list in a loop and assigning the current vList value to a variable doesn't seem to work as it assign out that vList value to all of the variables. Any suggestions would be