Skip to content

Fast Evaluator should allow Functional Interfaces #225

@otbutz

Description

@otbutz

Example:

DoubleUnaryOperator op = new ExpressionEvaluator().createFastEvaluator("a * 0.9", DoubleUnaryOperator.class, "a");
double value = op.applyAsDouble(100);
System.out.println(value);

We should relax the current check to follow the JLS definition of Functional Interfaces instead:

A functional interface is an interface that has just one abstract method (aside from the methods of Object), and thus represents a single function contract.

        for (Method method : interfaceToImplement.getDeclaredMethods()) {
            int mod = method.getModifiers();
            if (method.isDefault() || Modifier.isStatic(mod) || !Modifier.isPublic(mod)) {
                continue;
            }
            if (methodToImplement != null) {
                throw new InternalCompilerException(
                        "Interface \""
                                + interfaceToImplement
                                + "\" must declare exactly one abstract method"
                );
            }
            methodToImplement = method;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions