Skip to content

Conversation

joeferner
Copy link

Fixes LANG-1597 and LANG-1782

The current implementation discarded methods which could be potential matches because the matching was way to strict. This change loosens the check to allow any assignable values. The change also checks all variable arguments instead of just the last argument.

To facilitate various number types and conversion
NumberUtils.convertIfNotNarrowing was also introduced. This allows integers to be passed to methods which take Long... varargs

…s are supplied and when the supplied varargs don't match the exact class

The current implementation discarded methods which could be potential
matches because the matching was way to strict. This change loosens the
check to allow any assignable values. The change also checks all
variable arguments instead of just the last argument.

To facilitate various number types and conversion
NumberUtils.convertIfNotNarrowing was also introduced. This allows
integers to be passed to methods which take Long... varargs
Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @joeferner
Thank you for your updates. Please rebase on git master and see my comments.

* value</li>
* </ul>
*/
public static <T extends Number> T convertIfNotNarrowing(Number number, Class<T> targetType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep all of this package-private in the .reflect package.

}

// Perform conversion
if (targetType == Byte.class) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about char primitives?

/**
* Returns a numeric rank for the specified number type to determine
* its position in the widening conversion hierarchy.
* <p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to link to the JLS to show canonical definitions.

@@ -994,6 +1012,16 @@ void testInvokeJavaVarargsOverloadingResolution() throws Exception {
(Object[]) ArrayUtils.EMPTY_CLASS_ARRAY));
}

@Test
void testInvokeJavaVarargsResolution() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover all of the getRank() cases?

What about char?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants