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

Implement the functions of the Utils classes as Kotlin extension functions.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • lang.*
    • None

    Description

      This would provide the following advantages:

      Conciseness - Kotlin code is overall much more concise than Java code. For instance, the following method in BooleanUtils:

      public static Boolean negate(final Boolean bool) {
          if (bool == null) {
              return null;
          }
          return bool.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
      }
      

      can be represented as a single line in Kotlin:

      fun Boolean?.negate() = this?.not()
      

      Compatibility with Java - Kotlin extension functions are compiled as static methods in Java bytecode, so existing code that makes use of Apache Commons Lang will not be affected by the conversion.

      Kotlin support - Extension functions can be called in Kotlin code as if they were part of the original class declaration. For instance, the above method can be called as follows:

      val bool: Boolean? = null
      bool.negate() // returns null
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Isira Seneviratne Isira Seneviratne
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: