簡體   English   中英

Java獲得一套

[英]Java get set one liner

我想像這樣獲取並設置為null。

Foo foo = new Foo();
...
String test = foo.getTest() == null ? foo.setTest("this") : foo.getTest();

設置的東西是無效方法。 將此String test設置為的正確方法是什么?

不要使用一個內膽。

String test = foo.getTest();
if (test == null) {
    test = "this";
    foo.setTest(test);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM