0

I'm just copying the example from this github project page without any change and it's giving me a compile error

To reproduce, add this dependency to your pom

<dependency>
  <groupId>com.hankcs</groupId>
  <artifactId>aho-corasick-double-array-trie</artifactId>
  <version>1.2.1</version>
</dependency>

Then try to run this:

    // Collect test data set
    TreeMap<String, String> map = new TreeMap<String, String>();
    String[] keyArray = new String[]
            {
                    "hers",
                    "his",
                    "she",
                    "he"
            };
    for (String key : keyArray)
    {
        map.put(key, key);
    }
    // Build an AhoCorasickDoubleArrayTrie
    AhoCorasickDoubleArrayTrie<String> acdat = new AhoCorasickDoubleArrayTrie<String>();
    acdat.build(map);
    // Test it
    final String text = "uhers";
    acdat.parseText(text, (begin, end, value) -> {
        System.out.printf("[%d:%d]=%s\n", begin, end, value);
    });

The compile error is

The method parseText(CharSequence, AhoCorasickDoubleArrayTrie.IHit<String>) is ambiguous for the type AhoCorasickDoubleArrayTrie<String>

Please let me know if you need anything to clarify. You should be able to reproduce this with what I have provided here though.

Also, it's been suggested this may be a duplicate question when I posted this previously, but I do not think that's the case as that question is not related to lambda functions. If I'm wrong, please help me understand how that question's answer can resolve what I'm experiencing

4

1 回答 1

1

AhoCorasickDoubleArrayTrie有两种方法称为parseText,一种带有IHit,另一种带有IHitCancellable作为参数。两个接口都声明了一个方法boolean hit(int begin, int end, V value),因此通过使用 lambda,编译器不知道您打算调用什么方法。

我还没有通过谷歌搜索找到一个快速的解决方案,但你可以做的是声明你自己的类扩展AhoCorasickDoubleArrayTrie了一个自己的方法,该方法在具有你想要使用的接口的超类中调用预期的方法,例如

void myParseText(String text, IHit<V> hit) {
    super.parseText(text, hit);
}
于 2019-01-31T22:46:48.917 回答