Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024835

Improve method implementations that accept temporal interface parameters

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P3
    • Resolution: Fixed
    • 8
    • 8
    • core-libs
    • 8
    • b112
    • Verified

    Description

      Some methods that accept an interface such as Temporal will do an “instanceof” check and throw an exception if the two classes do not match.
      A reasonable effort should be made to honor the interface before throwing an exception.
      For example ZonedDateTime, Instant, and OffsetDateTime can all represent a point on the timeline.
      If calculating the amount of time between an Instant and a OffsetDateTime, you’d have to use the “from()” method to cast one of the objects before calculating the time between them. Not doing so will result in an exception being thrown at runtime.
      Interfaces should be honored as much as possible otherwise poor coding patterns such as the following could emerge in code that uses the java.time api.

      if(param instanceof LocalDateTime){
         finalParam = param;
      } else {
         finalParam = LocalDateTime.from(param);
      }


      See JSR 310 issue: 328 https://github.com/ThreeTen/threeten/issues/328

      Attachments

        Activity

          People

            rriggs Roger Riggs
            rriggs Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: