I get `SolrParser.kt:9:9 Class '<anonymous>' is no...
# k2-adopters
h
I get
SolrParser.kt:9:9 Class '<anonymous>' is not abstract and does not implement abstract member 'containsKey'
when extending a java class anonymously in K2. This works fine in 1.9.x. Any ideas how to fix this? Local object:
Copy code
object SolrParser {
    @JvmStatic
    fun asInputDoc(keysAndValues: Map<String, Any?>): SolrInputDocument =
        object : SolrInputDocument() {
            init {
                keysAndValues.forEach { (key, value) -> addField(key, value) }
            }
        }
From solr-solrj-9.6.0.jar:
Copy code
public class SolrInputDocument extends SolrDocumentBase<SolrInputField, SolrInputDocument>
    implements Iterable<SolrInputField> {
  ...

  @Override
  public boolean containsKey(Object key) {
    return _fields.containsKey(key);
  }
d
Hi. ~Could you please report this issue to kotl.in/issue?~ I created KT-68362
The workaround is to explicitly override reported functions I checked, this compiles fine:
Copy code
object SolrParser {
    @JvmStatic
    fun asInputDoc(keysAndValues: Map<String, Any?>): SolrInputDocument =
        object : SolrInputDocument() {
            init {
                keysAndValues.forEach { (key, value) -> addField(key, value) }
            }

            override fun containsKey(key: String?): Boolean {
                return super.containsKey(key)
            }

            override fun get(key: String?): SolrInputField? {
                return super.get(key)
            }

            override fun remove(key: String?): SolrInputField? {
                return super.remove(key)
            }
        }
}
h
Thanks! Hope this'll be sorted in the next version 🙂