1

I am new to this, I have this:

public Builder id (String val)
{
    id = val;
    return this;
}

from below if statement i want to set builder id = 1ac. How can I do that. Thank you

if (blah blah)
{
    id = "1ac";
}

2 Answers 2

6

I think you're looking for:

if(someCondition) builder.id("1ac");

The id method is written so that you pass it the value you want to set and then it returns this so you can chain calls together to set different values with a single statement.

Sign up to request clarification or add additional context in comments.

Comments

-1

I think you're looking for something more like this:

String idNew;    

public Builder id( String val )     
{             
  idNew = val;
  return idNew;     
} 

if(blah blah)
{
  id("1ac");
}

Or, of course, what the guy above me said. Either or.

1 Comment

You are returning a String when the method is meant to return a Builder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.