Differences between revisions 2 and 0
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
!'''[http://generic-viagra.land.ru/ | Generic viagra online] !''' !'''[http://cheap-phentermine.hotmail.ru/ | buy phentermine cheap phentermine online] !''' !'''[http://best-phentermine.hotmail.ru/ | buy cheap phentermine online] !''' !'''[http://fha_mortgage.chat.ru/ | buy cheap phentermine online] !''' !'''[http://ticket1_broker.chat.ru/ | Ticket Broker] !''' !'''[http://buy_phent.chat.ru/ | buy adipex phentermine] !''' !'''[http://cheap--viagra.fromru.com/ | Cheap viagra] !'''! |
#acl YoonKyungKoo:read,write All:read = Null Check Tip = |
Line 9: | Line 4: |
!'''[http://united-airline.boom.ru/ | United Airlines tickets flights] !'''! !'''[http://computer-desk.fromru.com/ | Computer desk] !'''! |
August 04, 2004 |
Line 12: | Line 6: |
[http://online1degree.chat.ru/ | Online degree] [http://camel-cig.newmail.ru | Cheap camel cigarettes] [http://marlb-cigarette.newmail.ru | marlboro cigarettes] [http://gift_basket.chat.ru/ | Gift basket] [http://find-tires.com/ | Best Tires] [http://acyclovir_online.chat.ru/ | acyclovir online] [http://acyclovir_cheap.chat.ru/ | acyclovir cheap] [http://zovirax_acyclovi.chat.ru/ | zovirax acyclovir] [http://acyclovir_medica.chat.ru/ | acyclovir medication] [http://acyclovir_cream.chat.ru/ | acyclovir cream] [http://acyclovir_ointme.chat.ru/ | acyclovir ointment] [http://discount_acyclov.chat.ru/ | discount acyclovir] [http://lamisil_canada.chat.ru/ | lamisil canada] [http://generic_lamisil.chat.ru/ | generic lamisil] [http://buy_lamisil.chat.ru/ | buy lamisil] [http://lamisil_cream.chat.ru/ | lamisil cream] [http://lamisil_online.chat.ru/ | lamisil online] [http://skin_zinc.chat.ru/ | skin zinc] [http://betadine_solutio.chat.ru/ | betadine solution] [http://tamiflu.chat.ru/ | tamiflu] [http://buy_tamiflu.chat.ru/ | buy tamiflu] [http://purchase_tamiflu.chat.ru/ | purchase tamiflu] |
Steve Maguire가 쓴 Writing Solid Code라는 책에서 보면 다음 코딩 관습의 차이를 이야기합니다. {{{#!cplusplus if (ch = '\t') ExpandTab(); if ('\t' = ch) ExpandTab(); }}} 이 두 개의 문장은 잘못된 코딩 예입니다. 원한 것은 {{{if (ch == '\t') ExpandTab();}}} 였으니까요. 하지만, Steve는 {{{if ('\t' == ch) ExpandTab();}}} 와 같이 코딩을 하기를 요구합니다. 위의 잘못된 두 문장 중 아래 문장은 리터럴에 변수값을 대입하려고 시도하기 때문에 컴파일러 에러가 발생해서 에러를 검사할 수 있기 때문이지요. 물론 자바에서는 boolean이 int 와 같은 Cardinal들과는 구분되기 때문에 위와 같은 오류는 언어 차원에서 막아줍니다. 그 대신 객체의 null 값을 적절하게 검사하지 않아 RuntimeException인 NullPointerException이 발생하는 코드를 종종 보게 됩니다. 이것을 줄일 수 있는 코딩 관습이 있습니다. 아래 두 문장은 하는 일이 동일합니다. {{{#!java if (a.equals("Hello")) doHello(); if ("Hello".equals(a)) doHello(); }}} 하지만 두번째 문장이 더 나은데 그 이유는 a에 대한 null 검사가 이루어진다는 점입니다. 자바는 equals() 메소드에 인자로 null이 들어오면 항상 false를 return하도록 요구하고 있습니다. 첫번째 문장의 경우 a가 null이면 NullPointerException이 발생하지만, 두번째 문장의 경우에는 정상적으로 처리가 됩니다. 이와 같이 null을 검사하여 NPE를 발생하지 않는 메소드나 연산자를 활용하면 좀더 깔끔한 코드를 작성할 수 있습니다. 예를 들어 instanceof 연산자의 경우 {{{#!java (null instanceof String) }}} 과 같은 문장은 항상 false를 return합니다. 사실 이러한 결과는 null이 어떤 클래스로도 캐스팅이 가능하다는 점을 생각하면 약간 의아하게 느껴질지도 모르겠습니다. instanceof 의 이 특성을 활용하면 equals() 메소드를 오버라이드하여 구현할 때 별도로 null 체크를 하지 않아도 됩니다. {{{#!java public void equals(Object object) { if (!(object instanceof MyClass)) { // null인지 검사하지 않아도 됨 return false; } // .... } }}} |
Line 36: | Line 59: |
Best links: '''mediterranean cruise''' |
여름이 한창입니다. 건강 관리 잘해서 멋진 소프트웨어를.... Happy Null Checking!!! |
Line 38: | Line 62: |
[http://mediterraneancru.euro.ru/ | mediterranean cruise] [http://mediterranean-cruise.fromru.com/ | mediterranean cruise] |
Posted by Yoon Kyung Koo at August 4, 2004 03:31 PM |
Line 41: | Line 64: |
Comments | |
Line 42: | Line 66: |
Best links: '''Messenger Bags''' [http://messenger_bags.chat.ru/ | messenger bag] [http://leather_messenge.chat.ru/ | leather messenger bag] [http://canvas_messenger.chat.ru/ | canvas messenger bag] [http://laptop_messenger.chat.ru/ | laptop messenger bag] [http://prada_messenger_.chat.ru/ | prada messenger bag] [http://gucci_messenger_.chat.ru/ | gucci messenger bag] [http://man_messenger_ba.chat.ru/ | man messenger bag] [http://louis_vuitton_me.chat.ru/ | louis vuitton messenger bag] [http://messenger_diaper.chat.ru/ | messenger diaper bag] [http://school_messenger.chat.ru/ | school messenger bag] [http://roxy_messenger_b.chat.ru/ | roxy messenger bag] [http://bike_messenger_b.chat.ru/ | bike messenger bag] [http://kenneth_cole_mes.chat.ru/ | kenneth cole messenger bag] [http://corduroy_messeng.chat.ru/ | corduroy messenger bag] [http://sling_messenger_.chat.ru/ | sling messenger bag] [http://man_leather_mess.chat.ru/ | man leather messenger bag] [http://puma_messenger_b.chat.ru/ | puma messenger bag] [http://small_messenger_.chat.ru/ | small messenger bag] [http://messenger_bag_sa.chat.ru/ | messenger bag sale] [http://jansport_messeng.chat.ru/ | jansport messenger bag] [http://messenger_should.chat.ru/ | messenger shoulder bag] [http://kate_spade_messe.chat.ru/ | kate spade messenger bag] [http://black_messenger_.chat.ru/ | black messenger bag] [http://coach_messenger_.chat.ru/ | coach messenger bag] [http://vintage_leather_.chat.ru/ | vintage leather messenger bag] [http://diesel_messenger.chat.ru/ | diesel messenger bag] [http://backpack_m_bag.chat.ru/ | backpack messenger bag] [http://nike_mess_bag.chat.ru/ | nike messenger bag] [http://computer_messbag.chat.ru/ | computer messenger bag] [http://cheap_messenger_.chat.ru/ | cheap messenger bag] [http://messenger_book_b.chat.ru/ | messenger book bag] [http://womens_messenger.chat.ru/ | womens messenger bag] [http://urban_messenger_.chat.ru/ | urban messenger bag] [http://timbuktu_messeng.chat.ru/ | timbuktu messenger bag] [http://custom_m_bag.chat.ru/ | custom messenger bag] [http://nylon_msg_bag.chat.ru/ | nylon messenger bag] [http://best_messenger_b.chat.ru/ | best messenger bag] [http://wholesale_messen.chat.ru/ | wholesale messenger bag] Best links: '''mortgage''' [http://arizona_mortgage.chat.ru/ | arizona mortgage] [http://arizona-mortgage.fromru.com/ | arizona mortgage] Best links: '''movie rental''' [http://movie_rental.euro.ru/ | movie rental] [http://movie-rental.fromru.com/ | movie rental] Best links: '''movie tickets''' [http://movie_tickets.chat.ru/ | movie ticket] [http://movie-tickets.fromru.com/ | movie ticket] Best links: '''moving services''' [http://moving_services.chat.ru/ | moving services] [http://distance_long_mo.chat.ru/ | distance long moving professional service state] [http://self_service_mov.chat.ru/ | self service moving] [http://moving_service_c.chat.ru/ | moving service chicago] [http://moving_service_l.chat.ru/ | moving service los angeles] [http://moving_service_w.chat.ru/ | moving service washington dc] [http://moving_service_d.chat.ru/ | moving service dallas] [http://moving_service_n.chat.ru/ | moving service new york] [http://moving_service_h.chat.ru/ | moving service houston] [http://moving_service_p.chat.ru/ | moving service phoenix] [http://moving_service_b.chat.ru/ | moving service boston] [http://moving4_service_.chat.ru/ | moving service philadelphia] [http://moving_service_s.chat.ru/ | moving service san francisco] [http://moving3_service_.chat.ru/ | moving service detroit] [http://moving8_service_.chat.ru/ | moving service st louis] Best links: '''music searcher''' [http://musicsearcher.fromru.com/ | music search] Best links: '''online''' [http://online1_gambling.chat.ru/ | online gambling] [http://online8_casino.chat.ru/ | online casino] [http://online0_poker.chat.ru/ | online poker] [http://poker2_online.chat.ru/ | poker online] [http://casino2_online.chat.ru/ | casino online] [http://gambling7_online.chat.ru/ | gambling online] [http://online2_degree.chat.ru/ | online degree] [http://online8_college.chat.ru/ | online college] [http://college8_online.chat.ru/ | college online] [http://online_trading.chat.ru/ | online trading] [http://online1_schools.chat.ru/ | online schools] [http://online_dating_se.chat.ru/ | online dating service] [http://online3_dating.chat.ru/ | online dating] [http://online_game.chat.ru/ | online game] [http://free_online_dati.chat.ru/ | free online dating] [http://online_auction.chat.ru/ | online auction] [http://free_online_game.chat.ru/ | free online game] [http://online_dating_lo.chat.ru/ | online dating louisville] [http://digital_photo_on.chat.ru/ | digital photo online] [http://online8_pharmacy.chat.ru/ | online pharmacy] [http://online_universit.chat.ru/ | online university] [http://university_onlin.chat.ru/ | university online] [http://education7_onlin.chat.ru/ | education online] [http://online_stock_tra.chat.ru/ | online stock trading] [http://bachelor_degree_.chat.ru/ | bachelor degree online] [http://course_online.chat.ru/ | course online] [http://online_shopping.chat.ru/ | online shopping] [http://online_banking.chat.ru/ | online banking] [http://online1_dvd_rent.chat.ru/ | online dvd rental] [http://dvd_online.chat.ru/ | dvd online] [http://sell_online.chat.ru/ | sell online] [http://viagra8_online.chat.ru/ | viagra online] [http://bingo_online.chat.ru/ | bingo online] [http://free_online_bing.chat.ru/ | free online bingo] [http://online_degree_pr.chat.ru/ | online degree program] [http://hydrocodone_onli.chat.ru/ | hydrocodone online] [http://university_of_ph.chat.ru/ | university of phoenix online] [http://apply_online_for.chat.ru/ | apply online for credit card] [http://online_survey.chat.ru/ | online survey] [http://flower2_online.chat.ru/ | flower online] [http://online_bank.chat.ru/ | online bank] [http://buy_book_online.chat.ru/ | buy book online] [http://online_publishin.chat.ru/ | online publishing] [http://bank_of_america_.chat.ru/ | bank of america online banking] [http://flash_game_onlin.chat.ru/ | flash game online play] [http://online1_betting.chat.ru/ | online betting] [http://online_gaming.chat.ru/ | online gaming] [http://online_business.chat.ru/ | online business] [http://online_credit_re.chat.ru/ | online credit report] [http://online_jobs.chat.ru/ | online jobs] [http://online2_universi.chat.ru/ | online university degree] [http://mba_online.chat.ru/ | mba online] [http://online_music.chat.ru/ | online music] [http://america_online.chat.ru/ | america online] [http://dvd_movie_online.chat.ru/ | dvd movie online rental] [http://play_free_online.chat.ru/ | play free online game] [http://make_money_onlin.chat.ru/ | make money online] [http://online_advertisi.chat.ru/ | online advertising] [http://online9_insuranc.chat.ru/ | online insurance quote] [http://online2_college_.chat.ru/ | online college degree] [http://online_virtual_g.chat.ru/ | online virtual gambling] [http://online_master_de.chat.ru/ | online master degree] [http://drug_online.chat.ru/ | drug online] [http://business_degree_.chat.ru/ | business degree online] [http://investing_online.chat.ru/ | investing online] [http://online1_store.chat.ru/ | online store] [http://online_book.chat.ru/ | online book] [http://online_movie.chat.ru/ | online movie] [http://online_prescript.chat.ru/ | online prescription] [http://online_search_wh.chat.ru/ | online search white pages] [http://car_online.chat.ru/ | car online] [http://online_payment.chat.ru/ | online payment] [http://market_research_.chat.ru/ | market research online] [http://online_phentermi.chat.ru/ | online phentermine] [http://lortab1_online.chat.ru/ | lortab online] [http://online4_lortab.chat.ru/ | online lortab] [http://online_radio.chat.ru/ | online radio] [http://online2_computer.chat.ru/ | online computer course] [http://online6_college_.chat.ru/ | online college education] [http://online_broker.chat.ru/ | online broker] [http://online6_roulette.chat.ru/ | online roulette] [http://online1_slot.chat.ru/ | online slot] [http://tramadol_online.chat.ru/ | tramadol online] [http://online_criminal_.chat.ru/ | online criminal justice course] [http://online_car_insur.chat.ru/ | online car insurance] Best links: '''online college course''' [http://online-college.fromru.com/ | online college course] Best links: '''online pc games''' [http://online_pc_games.chat.ru/ | online pc games] Best links: '''Online Photo Sharing''' [http://photo_sharing.chat.ru/ | online photo sharing] [http://online-photo-sharing.fromru.com/ | online photo sharing] Best links: '''online poker games''' [http://online-poker-games.atspace.com/ | online poker games] Best links: '''online store''' [http://online_store.euro.ru/ | online store] [http://online-store.fromru.com/ | online store] Best links: '''order flower''' [http://order_flower.euro.ru/ | order flower] [http://order-flower.fromru.com/ | order flower] Best links: '''pan''' [http://cake_pan.chat.ru/ | cake pan] [http://pan_pot.chat.ru/ | pan pot] [http://pan_pizza.chat.ru/ | pan pizza] [http://cake_pan_wilton.chat.ru/ | cake pan wilton] [http://pan_trunks.chat.ru/ | pan trunks] [http://frying_pan.chat.ru/ | frying pan] [http://mass_pan.chat.ru/ | mass pan] [http://grill_pan.chat.ru/ | grill pan] [http://gold_pan.chat.ru/ | gold pan] [http://steel_pan.chat.ru/ | steel pan] Best links: '''party''' [http://party9_poker.chat.ru/ | party poker] [http://party2_supply.chat.ru/ | party supply] [http://party_favor.chat.ru/ | party favor] [http://bachelorette_par.chat.ru/ | bachelorette party] [http://party_invitation.chat.ru/ | party invitation] [http://party_poker_bonu.chat.ru/ | party poker bonus] [http://bachelor_party.chat.ru/ | bachelor party] [http://birthday_party_s.chat.ru/ | birthday party supply] [http://party1_dress.chat.ru/ | party dress] [http://party_decoration.chat.ru/ | party decoration] [http://pajamas_party.chat.ru/ | pajamas party] [http://party_supplys.chat.ru/ | party supplys] [http://kid_birthday_par.chat.ru/ | kid birthday party] [http://party_supply_sto.chat.ru/ | party supply store] [http://home_party.chat.ru/ | home party] [http://republican_party.chat.ru/ | republican party] [http://toga_party.chat.ru/ | toga party] Best links: '''pda''' [http://pda_accessory.chat.ru/ | pda accessory] [http://pda_software.euro.ru/ | pda software] [http://pda-software.fromru.com/ | pda software] Best links: '''perfume''' [http://perfume7.chat.ru/ | perfume] [http://discount_perfume.euro.ru/ | discount perfume] [http://perfume_store.chat.ru/ | perfume store] [http://wholesale_perfum.euro.ru/ | wholesale perfume] [http://cheap_perfume.chat.ru/ | cheap perfume] [http://womens_perfume.euro.ru/ | womens perfume] [http://discountperfume.chat.ru/ | discount perfume] [http://angel_perfume.chat.ru/ | angel perfume] [http://perfume0_store.chat.ru/ | perfume store] [http://perfume_bottle.chat.ru/ | perfume bottle] [http://french_perfume.chat.ru/ | french perfume] [http://lancome_perfume.chat.ru/ | lancome perfume] [http://versace_perfume.chat.ru/ | versace perfume] [http://perfume_oil.chat.ru/ | perfume oil] [http://wholesale9_perfu.chat.ru/ | wholesale perfume] [http://cheap0_perfume.chat.ru/ | cheap perfume] [http://womens7_perfume.chat.ru/ | womens perfume] [http://ralph_lauren_per.chat.ru/ | ralph lauren perfume] [http://perfume_outlet.chat.ru/ | perfume outlet] [http://creed_perfume.chat.ru/ | creed perfume] [http://calvin_klein_per.chat.ru/ | calvin klein perfume] [http://perfume_cologne.chat.ru/ | perfume cologne] [http://gucci_perfume.chat.ru/ | gucci perfume] [http://escada_perfume.chat.ru/ | escada perfume] [http://rose_perfume.chat.ru/ | rose perfume] [http://man_perfume.chat.ru/ | man perfume] [http://perfume_shop.chat.ru/ | perfume shop] [http://woman_perfume.chat.ru/ | woman perfume] [http://designer_perfume.chat.ru/ | designer perfume] [http://givenchy_perfume.chat.ru/ | givenchy perfume] [http://lovely_perfume.chat.ru/ | lovely perfume] [http://joy_perfume.chat.ru/ | joy perfume] [http://perfume_online.chat.ru/ | perfume online] [http://burberry_perfume.chat.ru/ | burberry perfume] [http://origin_perfume.chat.ru/ | origin perfume] [http://flower_perfume.chat.ru/ | flower perfume] [http://fragrance_perfum.chat.ru/ | fragrance perfume] [http://perfume_mania.chat.ru/ | perfume mania] [http://blonde_perfume.chat.ru/ | blonde perfume] [http://discounted_perfu.chat.ru/ | discounted perfume] [http://clean_perfume.chat.ru/ | clean perfume] [http://prada_perfume.chat.ru/ | prada perfume] [http://beautiful_perfum.chat.ru/ | beautiful perfume] [http://bargain_cosmetic.chat.ru/ | bargain cosmetic perfume] [http://opium_perfume.chat.ru/ | opium perfume] [http://discontinued_per.chat.ru/ | discontinued perfume] [http://antique_perfume_.chat.ru/ | antique perfume bottle] [http://perfume_miniatur.chat.ru/ | perfume miniature] [http://guess_perfume.chat.ru/ | guess perfume] [http://armani_perfume.chat.ru/ | armani perfume] [http://tiffany_perfume.chat.ru/ | tiffany perfume] [http://lacoste_perfume.chat.ru/ | lacoste perfume] [http://giorgio_armani_p.chat.ru/ | giorgio armani perfume] [http://venezia_perfume.chat.ru/ | venezia perfume] [http://kenzo_perfume.chat.ru/ | kenzo perfume] [http://channel_perfume.chat.ru/ | channel perfume] [http://best_perfume.chat.ru/ | best perfume] [http://paris_perfume.chat.ru/ | paris perfume] [http://white_diamonds_p.chat.ru/ | white diamonds perfume] [http://lalique_perfume.chat.ru/ | lalique perfume] [http://discount_designe.chat.ru/ | discount designer perfume] [http://wholesale_p_oil.chat.ru/ | wholesale perfume oil] [http://perfume_sale.chat.ru/ | perfume sale] Best links: '''pet''' [http://invis_pet_fence.chat.ru/ | invisible pet fence] [http://invisible-pet-fence.fromru.com/ | invisible pet fence] Best links: '''pet supply''' [http://pet-supply.atspace.com/ | pet supply] Best links: '''pizza hut''' [http://pizza-hut.fromru.com/ | pizza hut] Best links: '''play game''' [http://play_free_game.chat.ru/ | play free game] [http://play7_game.chat.ru/ | play game] [http://game1_to_play_on.chat.ru/ | game to play online] [http://play_casino_game.chat.ru/ | play casino game] [http://play9_online_vid.chat.ru/ | play online video game] [http://play_card_game.chat.ru/ | play card game] [http://play_free_yahoo_.chat.ru/ | play free yahoo game online] [http://free_car_game_to.chat.ru/ | free car game to play online] [http://play_card_game_o.chat.ru/ | play card game online] [http://play4_free_yahoo.chat.ru/ | play free yahoo game] [http://free_golf_game_t.chat.ru/ | free golf game to play online] [http://play_sonic_game_.chat.ru/ | play sonic game online] [http://play_kid_game.chat.ru/ | play kid game] [http://play_free_casino.chat.ru/ | play free casino game online] [http://play_online_mult.chat.ru/ | play online multiplayer game] [http://game_to_play_now.chat.ru/ | game to play now] [http://play3_poker_game.chat.ru/ | play poker game] [http://play_sims_game_o.chat.ru/ | play sims game online for free] [http://play3_casino_gam.chat.ru/ | play casino game online] [http://play_free_video_.chat.ru/ | play free video game online] [http://play47_free_onli.chat.ru/ | play free online shooting game] [http://play_cool_game.chat.ru/ | play cool game] [http://play2_free_casin.chat.ru/ | play free casino game] [http://play_online_bask.chat.ru/ | play online basketball game] [http://play9_free_onlin.chat.ru/ | play free online adventure game] [http://play_free_pool_g.chat.ru/ | play free pool game] [http://play_football_ga.chat.ru/ | play football game] [http://free_football_ga.chat.ru/ | free football game to play online] [http://kid_game_to_play.chat.ru/ | kid game to play online] [http://free_game_to_pla.chat.ru/ | free game to play now] [http://sympathy-giftb.fromru.com/ | sympathy gift basket] [http://baby-gb.pochta.ru/ | baby gift basket] [http://food_gb.chat.ru/ | food gift basket] [http://gourmet_gb.chat.ru/ | gourmet gift basket] [http://cookie_gift_b.chat.ru/ | cookie gift basket] |
{{{ 저는 최근 Writing Solid Code 책 보고 있습니다. 하지만 그 코드를 자바쪽에 적용하는건 생각하지 못했던 발상이네요. 좋은 정보 얻어 갑니다. :-) Posted by: 어리숙 at September 1, 2004 11:26 AM }}} |
Null Check Tip
August 04, 2004
Steve Maguire가 쓴 Writing Solid Code라는 책에서 보면 다음 코딩 관습의 차이를 이야기합니다.
1 if (ch = '\t') ExpandTab();
2
3 if ('\t' = ch) ExpandTab();
이 두 개의 문장은 잘못된 코딩 예입니다. 원한 것은 if (ch == '\t') ExpandTab(); 였으니까요.
하지만, Steve는 if ('\t' == ch) ExpandTab(); 와 같이 코딩을 하기를 요구합니다. 위의 잘못된 두 문장 중 아래 문장은 리터럴에 변수값을 대입하려고 시도하기 때문에 컴파일러 에러가 발생해서 에러를 검사할 수 있기 때문이지요.
물론 자바에서는 boolean이 int 와 같은 Cardinal들과는 구분되기 때문에 위와 같은 오류는 언어 차원에서 막아줍니다.
그 대신 객체의 null 값을 적절하게 검사하지 않아 RuntimeException인 NullPointerException이 발생하는 코드를 종종 보게 됩니다. 이것을 줄일 수 있는 코딩 관습이 있습니다. 아래 두 문장은 하는 일이 동일합니다.
1 if (a.equals("Hello")) doHello();
2 if ("Hello".equals(a)) doHello();
하지만 두번째 문장이 더 나은데 그 이유는 a에 대한 null 검사가 이루어진다는 점입니다. 자바는 equals() 메소드에 인자로 null이 들어오면 항상 false를 return하도록 요구하고 있습니다. 첫번째 문장의 경우 a가 null이면 NullPointerException이 발생하지만, 두번째 문장의 경우에는 정상적으로 처리가 됩니다.
이와 같이 null을 검사하여 NPE를 발생하지 않는 메소드나 연산자를 활용하면 좀더 깔끔한 코드를 작성할 수 있습니다. 예를 들어 instanceof 연산자의 경우
1 (null instanceof String)
과 같은 문장은 항상 false를 return합니다. 사실 이러한 결과는 null이 어떤 클래스로도 캐스팅이 가능하다는 점을 생각하면 약간 의아하게 느껴질지도 모르겠습니다.
instanceof 의 이 특성을 활용하면 equals() 메소드를 오버라이드하여 구현할 때 별도로 null 체크를 하지 않아도 됩니다.
1 public void equals(Object object) {
2 if (!(object instanceof MyClass)) { // null인지 검사하지 않아도 됨
3 return false;
4 }
5
6 // ....
7 }
여름이 한창입니다. 건강 관리 잘해서 멋진 소프트웨어를.... Happy Null Checking!!!
Posted by Yoon Kyung Koo at August 4, 2004 03:31 PM
Comments
저는 최근 Writing Solid Code 책 보고 있습니다. 하지만 그 코드를 자바쪽에 적용하는건 생각하지 못했던 발상이네요. 좋은 정보 얻어 갑니다. :-) Posted by: 어리숙 at September 1, 2004 11:26 AM