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

Improve method implementations that accept temporal interface parameters

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b112
    • Verification:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: