??????????????
????1. NULL ????????
?????????????? null ????????????????磬????????????÷????????? array ???? collection ?????? null ??????????????????????? NullPointerException????????????λ??????????????????????
????</>
????List<String> accountIds = person.getAccountIds();
????for (String accountId : accountIds) {
????processAccount(accountId);
????}
????????? person ??? account ?????getAccountIds() ?????? null ??????????? NullPointerException ??????????????????????????????????????? null ??滻???????? list????? NullPointerException ???????????????????????????????? accountId ?????飬????????????
????????????? null ???????????????????????????????????????????? Optional ??????????????????????????????Щ???????
????</>
????Optional<String> optionalString = Optional.ofNullable(nullableString);
????if(optionalString.isPresent()) {
????System.out.println(optionalString.get());
????}
??????????Java8 ??????????????????
????</>
????Optional<String> optionalString = Optional.ofNullable(nullableString);
????optionalString.ifPresent(System.out::println);
????Java ??? Java8 ?汾?????? Optional ?????????????????????????????????????????????????? Google Guava ????? Java ??????汾????á?
????2. ??????
?????????????????????????????????????о???? Java ???????????????????????????????????????????????????????????????????????????????С??????£???????????????????????????????????????н????????????????????????????????????С???????????????????????????????????y????????д??????????
????</>
????selfie = person.shootASelfie();
????try {
????selfie.show();
????} catch (NullPointerException e) {
????// Maybe?? invisible man. Who cares?? anyway?
????}
??????????????????????????????????????????????????????????
????</>
????try { selfie.delete(); } catch (NullPointerException unimportant) {  }
????3. ?????????
???????????????????????????????????? iterator ????????????????????е?????????磬????????? hats ?б????????????????к? ear flaps ?????
????</>
????List<IHat> hats = new ArrayList<>();
????hats.add(new Ushanka()); // that one has ear flaps
????hats.add(new Fedora());
????hats.add(new Sombrero());
????for (IHat hat : hats) {
????if (hat.hasEarFlaps()) {
????hats.remove(hat);
????}
????}
??????????д????ConcurrentModificationException ????????????????????????????????????????????????????????????б???????????????????б????????????????????б???????????????????????
???????????в????????????????????????????????ò???????г??????????д???????????????????????????????????????Java ????????????????????????????С????