title: Kotlin: expecting menber declaration when it seems I have already done
body: <p>I found few questions with same error message but, as far I can see, I have declared it properly.</p>
  <p>Here is the whole code in Kotlin:</p>
  <pre><code>package com.mybank.service
  
  import org.reactivestreams.Publisher
  import com.mongodb.client.result.InsertOneResult
  import com.mongodb.reactivestreams.client.MongoClients
  import com.mongodb.reactivestreams.client.MongoClient
  import com.mongodb.reactivestreams.client.MongoCollection
  import com.mongodb.reactivestreams.client.MongoDatabase
  import java.util.Arrays
  import org.bson.Document
  
  class test {
  
  
      //MongoClient mongoClient = MongoClients.create();
      var mongoClient: MongoClient = MongoClients.create(&quot;mongodb://root:q@localhost:27017&quot;)
      var database: MongoDatabase = mongoClient.getDatabase(&quot;mydb&quot;)
      var collection: MongoCollection&lt;Document&gt; = database.getCollection(&quot;mycollection&quot;)
  
      var doc: Document = Document(&quot;name&quot;, &quot;MongoDB&quot;)
              .append(&quot;type&quot;, &quot;database&quot;)
              .append(&quot;count&quot;, 1)
              .append(&quot;versions&quot;, Arrays.asList(&quot;v3.2&quot;, &quot;v3.0&quot;, &quot;v2.6&quot;))
              .append(&quot;info&quot;, Document(&quot;x&quot;, 203).append(&quot;y&quot;, 102))
  
  
      //publisher decalred and initialized
      var publisher: Publisher&lt;InsertOneResult&gt; = collection.insertOne(doc)
  
      publisher *** why publisher isn't initialized yet???
  </code></pre>
  <p>It is working in java that way</p>
  <pre><code>imports ommited, same as above
  public class App {
      public static void main(String[] args) throws Throwable {
  
          //MongoClient mongoClient = MongoClients.create();
          MongoClient mongoClient = MongoClients.create(&quot;mongodb://root:q@localhost:27017&quot;);
          MongoDatabase database = mongoClient.getDatabase(&quot;mydb&quot;);
          MongoCollection&lt;Document&gt; collection = database.getCollection(&quot;mycollection&quot;);
  
          Document doc = new Document(&quot;name&quot;, &quot;MongoDB&quot;)
                  .append(&quot;type&quot;, &quot;database&quot;)
                  .append(&quot;count&quot;, 1)
                  .append(&quot;versions&quot;, Arrays.asList(&quot;v3.2&quot;, &quot;v3.0&quot;, &quot;v2.6&quot;))
                  .append(&quot;info&quot;, new Document(&quot;x&quot;, 203).append(&quot;y&quot;, 102));
  
  
          Publisher&lt;InsertOneResult&gt; publisher = collection.insertOne(doc);
  
          publisher.subscribe(new Subscriber&lt;InsertOneResult&gt;() {
              @Override
              public void onSubscribe(final Subscription s) {
                  s.request(1);  // &lt;--- Data requested and the insertion will now occur
              }
  
              @Override
              public void onNext(final InsertOneResult result) {
                  System.out.println(&quot;Inserted: &quot; + result);
              }
  
              @Override
              public void onError(final Throwable t) {
                  System.out.println(&quot;Failed&quot;);
              }
  
              @Override
              public void onComplete() {
                  System.out.println(&quot;Completed&quot;);
              }
          });
  
          //all examples
          collection.countDocuments()
                  .subscribe(new SubscriberHelpers.PrintSubscriber&lt;Long&gt;(&quot;total # of documents after inserting &quot;
                          + &quot; is: %s&quot;));
  
          collection.find(eq(&quot;name&quot;, &quot;MongoDB&quot;)).first().subscribe(new SubscriberHelpers.PrintDocumentSubscriber());
  
          Thread.sleep(1000);
  
      }
  
  }
  </code></pre>
  <p>The error message:</p>
  <p><a href="https://i.stack.imgur.com/sbYq5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sbYq5.png" alt="IntelliJ" /></a></p>
  <p>I am not coding to Android and here is the build.gradle althought I think it is not relevant</p>
  <pre><code>plugins {
      id &quot;org.jetbrains.kotlin.jvm&quot; version &quot;1.3.72&quot;
      id &quot;org.jetbrains.kotlin.kapt&quot; version &quot;1.3.72&quot;
      id &quot;org.jetbrains.kotlin.plugin.allopen&quot; version &quot;1.3.72&quot;
      id &quot;application&quot;
      id 'com.google.protobuf' version '0.8.13'
  }
  
  version &quot;0.2&quot;
  group &quot;account-control&quot;
  
  repositories {
      mavenLocal()
      jcenter()
  }
  
  configurations {
      // for dependencies that are needed for development only
      developmentOnly
  }
  
  dependencies {
      kapt(enforcedPlatform(&quot;io.micronaut:micronaut-bom:$micronautVersion&quot;))
      kapt(&quot;io.micronaut:micronaut-inject-java&quot;)
      kapt(&quot;io.micronaut:micronaut-validation&quot;)
  
      implementation(enforcedPlatform(&quot;io.micronaut:micronaut-bom:$micronautVersion&quot;))
      implementation(&quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}&quot;)
      implementation(&quot;org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}&quot;)
      implementation(&quot;org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion&quot;)
      implementation(&quot;io.micronaut:micronaut-runtime&quot;)
  //    implementation(&quot;io.micronaut.grpc:micronaut-grpc-runtime&quot;)
      implementation(&quot;io.micronaut.grpc:micronaut-grpc-server-runtime:$micronautGrpcVersion&quot;)
      implementation(&quot;io.micronaut.grpc:micronaut-grpc-client-runtime:$micronautGrpcVersion&quot;)
      implementation(&quot;io.grpc:grpc-kotlin-stub:${grpcKotlinVersion}&quot;)
  
      //Kafka
      implementation(&quot;io.micronaut.kafka:micronaut-kafka&quot;)
  
      //vertx
      implementation(&quot;io.micronaut.sql:micronaut-vertx-mysql-client&quot;)
      //implementation(&quot;io.micronaut.configuration:micronaut-vertx-mysql-client&quot;)
      compile 'io.vertx:vertx-lang-kotlin:3.9.4'
  
      //mongodb
      implementation(&quot;org.mongodb:mongodb-driver-reactivestreams:4.1.1&quot;)
  
      runtimeOnly(&quot;ch.qos.logback:logback-classic:1.2.3&quot;)
      runtimeOnly(&quot;com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8&quot;)
  
      kaptTest(&quot;io.micronaut:micronaut-inject-java&quot;)
  
      testImplementation enforcedPlatform(&quot;io.micronaut:micronaut-bom:$micronautVersion&quot;)
      testImplementation(&quot;org.junit.jupiter:junit-jupiter-api:5.3.0&quot;)
      testImplementation(&quot;io.micronaut.test:micronaut-test-junit5&quot;)
      testImplementation(&quot;org.mockito:mockito-junit-jupiter:2.22.0&quot;)
  
      testRuntime(&quot;org.junit.jupiter:junit-jupiter-engine:5.3.0&quot;)
      testRuntime(&quot;org.jetbrains.spek:spek-junit-platform-engine:1.1.5&quot;)
  }
  
  test.classpath += configurations.developmentOnly
  
  mainClassName = &quot;account-control.Application&quot;
  
  test {
      useJUnitPlatform()
  }
  
  allOpen {
      annotation(&quot;io.micronaut.aop.Around&quot;)
  }
  
  compileKotlin {
      kotlinOptions {
          jvmTarget = '11' 
          //Will retain parameter names for Java reflection
          javaParameters = true 
      }
  }
  //compileKotlin.dependsOn(generateProto)
  
  compileTestKotlin {
      kotlinOptions {
          jvmTarget = '11' 
          javaParameters = true 
      }
  }
  
  tasks.withType(JavaExec) {
      classpath += configurations.developmentOnly
      jvmArgs('-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
  }
  
  sourceSets {
      main {
          java {
              srcDirs 'build/generated/source/proto/main/grpc'
              srcDirs 'build/generated/source/proto/main/grpckt'
              srcDirs 'build/generated/source/proto/main/java'
          }
      }
  }
  
  protobuf {
      protoc { artifact = &quot;com.google.protobuf:protoc:${protocVersion}&quot; }
      plugins {
          grpc { artifact = &quot;io.grpc:protoc-gen-grpc-java:${grpcVersion}&quot; }
          grpckt { artifact = &quot;io.grpc:protoc-gen-grpc-kotlin:${grpcKotlinVersion}&quot; }
      }
      generateProtoTasks {
          all()*.plugins {
              grpc {}
              grpckt {}
          }
      }
  }
  </code></pre>
  <p>*** edited</p>
  <pre><code>package com.mybank.service
  
  import org.reactivestreams.Publisher
  import com.mongodb.client.result.InsertOneResult
  import com.mongodb.reactivestreams.client.MongoClients
  import com.mongodb.reactivestreams.client.MongoClient
  import com.mongodb.reactivestreams.client.MongoCollection
  import com.mongodb.reactivestreams.client.MongoDatabase
  import java.util.Arrays
  import org.bson.Document
  import javax.inject.Singleton
  
  class test {
  
  
      //MongoClient mongoClient = MongoClients.create();
      var mongoClient: MongoClient = MongoClients.create(&quot;mongodb://root:q@localhost:27017&quot;)
      var database: MongoDatabase = mongoClient.getDatabase(&quot;mydb&quot;)
      var collection: MongoCollection&lt;Document&gt; = database.getCollection(&quot;mycollection&quot;)
  
      var doc: Document = Document(&quot;name&quot;, &quot;MongoDB&quot;)
              .append(&quot;type&quot;, &quot;database&quot;)
              .append(&quot;count&quot;, 1)
              .append(&quot;versions&quot;, Arrays.asList(&quot;v3.2&quot;, &quot;v3.0&quot;, &quot;v2.6&quot;))
              .append(&quot;info&quot;, Document(&quot;x&quot;, 203).append(&quot;y&quot;, 102))
  
  
      //publisher decalred and initialized
      var publisher: Publisher&lt;InsertOneResult&gt; = collection.insertOne(doc)
  }
  </code></pre>
  <p>then in other class</p>
  <pre><code>@Singleton
  class TransactionService(){
  
      @Inject
      lateinit var test: test
  
      fun postDebitTransaction(debit: String) : String{
  
          test.publisher.subscribe(
                  object x: Subscriber&lt;InsertOneResult&gt; {
                      override fun onSubscribe(s: Subscription) {
                          s.request(1) // &lt;--- Data requested and the insertion will now occur
                      }
  
                      override fun onNext(result: InsertOneResult) {
                          println(&quot;Inserted: $result&quot;)
                      }
  
                      override fun onError(t: Throwable) {
                          println(&quot;Failed&quot;)
                      }
  
                      override fun onComplete() {
                          println(&quot;Completed&quot;)
                      }
                  })
  
          return &quot;posted&quot;
      }
  }
  </code></pre>
  <p>And I am getting</p>
  <p>Type mismatch.
  Required:
  Subscriber&lt;in InsertOneResult!&gt;!</p>
  <p>I am quite sure I am doing some silly error in Kotlin</p>