Skip to content

How to override overloads for standard library? #101

@LywLover

Description

@LywLover

Hello,
Is there a way to override overloads for standard library?
Below is part of my code which is not getting the expected result.

@NotNull private static final Overload OVERLOAD_MATCHES = Overload.binary(Overloads.MatchesString, (lhs, rhs) -> {
  System.out.println("---override matches---");
  String inst = (String) lhs.value();
  String target = (String) rhs.value();
  boolean result = target.matches(inst);
  return result ? BoolT.True : BoolT.False;
});

@Test public void testMatchs() {
  boolean result1 = XrayCEL.eval("'1234'.matches(r'\\d+')");
  System.out.println(result1); // output: true

  boolean result2 = XrayCEL.eval("r'\\d+'.matches('1234')");
  System.out.println(result2); // output: false
}

My override for matches is not be called, the log message are not be printed , it still used standard library's matches.

  • Standard -> string.matches(regexString)
  • Expected -> regexString.matches(string)

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