Reputation: 2615
I'd like to do a get and set if null like so.
Foo foo = new Foo();
...
String test = foo.getTest() == null ? foo.setTest("this") : foo.getTest();
The thing is set is a void method. What the right way to set this String test
to ?
Upvotes: 0
Views: 555
Reputation: 280102
Don't use a one liner.
String test = foo.getTest();
if (test == null) {
test = "this";
foo.setTest(test);
}
Upvotes: 3