Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1674

Range construction with abstract/derived classes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.13.0
    • None
    • None

    Description

      The constructors for org.apache.commons.lang3.Range don't play nicely with abstract/derived classes. Example:

      abstract class AbstractComparable implements Comparable<AbstractComparable> {
      @Override public int compareTo(AbstractComparable o) {}
      }

      class DerivedA extends AbstractComparable {}

      class DerivedB extends AbstractComparable {}

      // compiles, and reasonable since AbstractComparable is the common parent
      static final Range<AbstractComparable> RANGE_MIXED = Range.between(new DerivedA(), new DerivedB());

      // compiles, but unreasonable to force usage of parent class
      static final Range<AbstractComparable> RANGE_SAME_CLASS = Range.between(new DerivedA(), new DerivedA());

      // compiler error
      static final Range<DerivedA> RANGE_A = Range.between(new DerivedA(), new DerivedA());

      // compiler error
      static final Range<DerivedB> RANGE_B = Range.is(new DerivedB());

      Attachments

        Activity

          People

            Unassigned Unassigned
            balsingh Baljit Singh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h 10m
                2h 10m