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

Reduce redundancy of FunctionPointer construction

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      Consider the following method signature:

      < T, R > R mapOrNull( T value, Function< ? super T, R > mapper );

      A call would look like this:

      DetailType detail = mapOrNull( myValue, TypeOfMyValue::getDetail );

      Here the TypeOfMyValue is redundant and doesn't necessarily help for readability. The call could look like this:

      DetailType detail = mapOrNull( myValue, ::getDetail );

      If there is one argument, that clarifies the type to refer to, then all function pointer constructions could skip it.

      There is just one thing to distinguish: pointer to an instance method of myValue or to a method of that class. The compile could decide using the following criteria.

      // ::getDetail means myValue::getDetail
      DetailType detail = mapOrNull( myValue, ::getDetail );
      // :::getDetail means TypeOfMyValue::getDetail
      DetailType detail = mapOrNull( myValue, :::getDetail );

      Wouldn't that be a simplification?

      The argument, that clarifies the referenced type would not have to be the first, not stand left to others, that use the type. Hence, if could also look like this.

      < T > int indexOf( Predicate< T > comparator, T... array );

      indexOf( :::test, myArray );

      where myArray is an array of class X, that defines a method test, compatible with a predicate.


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: