根据Solr's blog ,Lucene要求TokenFilter子类必须声明为final。在这种情况下,期末类(class)的优势是什么?它使得扩展现有 TokenFilter 的功能变得不可能。
最佳答案
TokenFilter
扩展了 TokenStream
,它的 Javadoc 说:
The
TokenStream
-API in Lucene is based on the decorator pattern. Therefore all non-abstract subclasses must be final or have at least a final implementation ofincrementToken()
! This is checked when Java assertions are enabled.
例如,StandardFilter
未标记为 final
(只有 incrementToken()
标记为)。
因此,如果您想扩展现有的 TokenFilter
,最好通过委托(delegate)来实现。
关于java - 为什么 Lucene Token Filter 类必须声明为 "final"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23938894/