Look at the Java code that hurts.

Source: Internet
Author: User
Tags throw exception

Project on the basis of existing code development, but encountered a lot of egg pain code. For example, here's a look at how many slots you can find:

1      Public StaticString Adddate (string date, string into)throwsException2     {3String sdate = "";4         Try5         {6Date = Date.replaceall ("-", "/");7Date = date.substring (0, Date.length ()-2);8GregorianCalendar GRC =NewGregorianCalendar ();9Grc.settime (NewDate (date));Ten Grc.add (Gregoriancalendar.date, Integer.parseint (into)); OneSimpleDateFormat formatter =NewSimpleDateFormat ("Yyyy-mm-dd"); ASdate =NewString (Formatter.format (Grc.gettime ())); -         } -         Catch(Exception e) the         { -             Throwe; -         } -         returnsdate; +}

1. Catch exception and throw away, Adddate would have to throw exception,try purely superfluous

2. The sdate variable is purely superfluous

3. Formatter.format would have returned a string, and a new string, a purely superfluous

Look at the Java code that hurts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.