throw new BootstrapMethodError("Invalid number of parameters for method call"); throw new BootstrapMethodError("Illegal parameter for method call: " + args[0]); throw new BootstrapMethodError("Illegal recipe for method call: too many bits"); throw new BootstrapMethodError("Illegal number of parameters: expected " + numLambdas + " references"); case INDEX_NORMALIZE: if (args.length > 0) { throw new BootstrapMethodError("Illegal static bootstrap parameters for flavor: " + flavor); throw new BootstrapMethodError("Invalid number of parameters for reference call"); throw new BootstrapMethodError("Illegal parameter for reference call: " + args[0]); case BINARY_OPERATOR: if (args.length != 1) { throw new BootstrapMethodError("Invalid number of parameters for operator call"); throw new BootstrapMethodError("Illegal parameter for reference call: " + args[0]); throw new BootstrapMethodError("This parameter is only supported for BINARY_OPERATORs"); throw new BootstrapMethodError("This parameter is only supported for BINARY/SHIFT_OPERATORs"); throw new BootstrapMethodError("Illegal static bootstrap parameter for flavor: " + flavor);
@Override SingleDynamicMethod getMethodForExactParamTypes(final String paramTypes) { final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>(); for(final SingleDynamicMethod method: methods) { final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes); if(matchingMethod != null) { matchingMethods.add(matchingMethod); } } switch(matchingMethods.size()) { case 0: { return null; } case 1: { return matchingMethods.getFirst(); } default: { throw new BootstrapMethodError("Can't choose among " + matchingMethods + " for argument types " + paramTypes + " for method " + getName()); } } }
@Override SingleDynamicMethod getMethodForExactParamTypes(String paramTypes) { final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>(); for(SingleDynamicMethod method: methods) { final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes); if(matchingMethod != null) { matchingMethods.add(matchingMethod); } } switch(matchingMethods.size()) { case 0: { return null; } case 1: { return matchingMethods.getFirst(); } default: { throw new BootstrapMethodError("Can't choose among " + matchingMethods + " for argument types " + paramTypes + " for method " + getName()); } } }
private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) { if(descriptor.getMethodType().parameterCount() != paramCount) { throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters."); } }
private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) { if(descriptor.getMethodType().parameterCount() != paramCount) { throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters."); } }
private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) { if(descriptor.getMethodType().parameterCount() != paramCount) { throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters."); } } }
private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) { if(descriptor.getMethodType().parameterCount() != paramCount) { throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters."); } } }
public static void main(String... arg) { Consumer<String> consumer=getConsumer(); consumer.accept("hello world"); } static Consumer<String> getConsumer() { try { MethodHandles.Lookup lookup=MethodHandles.lookup(); MethodType consumeString = MethodType.methodType(void.class, String.class); return (Consumer<String>)LambdaMetafactory.metafactory(lookup, "accept", MethodType.methodType(Consumer.class, PrintStream.class), consumeString.changeParameterType(0, Object.class), lookup.findVirtual(PrintStream.class, "println", consumeString), consumeString) .getTarget().invokeExact(System.out); } catch(RuntimeException | Error e) { throw e; } catch(Throwable t) { throw new BootstrapMethodError(t); } }
throw new BootstrapMethodError("Can't choose among " + maximallySpecifics + " for argument types " + callSiteType);
throw new BootstrapMethodError("Can't choose among " + maximallySpecifics + " for argument types " + callSiteType);
PIC(PainlessLookup painlessLookup, Map<String, LocalMethod> localMethods, MethodHandles.Lookup methodHandlesLookup, String name, MethodType type, int initialDepth, int flavor, Object[] args) { super(type); if (type.parameterType(0) != Object.class) { throw new BootstrapMethodError("The receiver type (1st arg) of invokedynamic descriptor must be Object."); } this.painlessLookup = painlessLookup; this.localMethods = localMethods; this.methodHandlesLookup = methodHandlesLookup; this.name = name; this.flavor = flavor; this.args = args; this.depth = initialDepth; MethodHandle fallback = FALLBACK.bindTo(this) .asCollector(Object[].class, type.parameterCount()) .asType(type); setTarget(fallback); }