Skip to content

Commit

Permalink
Merge pull request #2689 from pdbain-ibm/nestmates
Browse files Browse the repository at this point in the history
Make MethodType.lastParameter() public
  • Loading branch information
DanHeidinga committed Sep 10, 2018
2 parents a61fe0f + 4b4c401 commit 669607a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,8 @@ public MethodHandle withVarargs(boolean isVarArityNeeded) throws IllegalArgument
if (isVarArityNeeded) {
/* Convert the handle if initially not with variable arity */
if (!this.isVarargsCollector()) {
Class<?> lastClass = null;
try {
/* An exception is thrown if the MethodType has no arguments */
lastClass = this.type.lastParameterType();
} catch(RuntimeException e) {
Class<?> lastClass = this.type.lastParameterType();
if (void.class == lastClass) { /* there were no arguments */
throw new IllegalArgumentException();
}
/* IllegalArgumentException will be thrown out from asVarargsCollector
Expand Down
17 changes: 12 additions & 5 deletions jcl/src/java.base/share/classes/java/lang/invoke/MethodType.java
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,21 @@ public Class<?> returnType(){
return returnType;
}

/* Return the last class in the parameterType array.
/**
* Return the last class in the parameterType array.
* This is equivalent to:
* type.parameterType(type.parameterCount() - 1)
* Will throw ArrayIndexOutOfBounds on bad indexes. This is a subclass of IndexOutOfBoundsException
* so this is valid when JCKs expect certain exceptions.
* @return class of final parameter, or void.class if there are no parameters
*/
/* package */ Class<?> lastParameterType() {
return arguments[arguments.length - 1];
/*[IF Java10]*/
public
/*[ENDIF]*/
Class<?> lastParameterType() {
Class<?> result = void.class;
if (arguments.length > 0) {
result = arguments[arguments.length - 1];
}
return result;
}

/**
Expand Down

0 comments on commit 669607a

Please sign in to comment.