title: Kotlin Error : 'public' function exposes its 'public/*package*/' return type argument
body: <p>I am new to Kotlin and trying out to write some project using the language.
  I am using Java library and extending a class from the library in my project and I am seeing this error message.</p>
  
  <pre><code>'public' function exposes its 'public/*package*/' return type argument FooSettings
  </code></pre>
  
  <p>I understand the problem is but I am not sure how to fix it in Kotlin since I am still trying get familiar with Kotlin.
  I can see that Kotlin is being smart and only trying to return of type that extends <code>FooSettings</code>. However the problem is <code>FooSettings</code> is package public only which means that I cannot access if in my Kotlin project.</p>
  
  <p>I did some research about Kotlin generics and use of <code>in</code> or <code>out</code> but I wasn't able to fix the problem.</p>
  
  <p>Is there any work around that I can do in my Kotlin project to fix the error I am seeing?</p>
  
  <h2>Code snippet</h2>
  
  <p><strong>This is sample of Java library class:</strong>
  Note, I have no way to changing the implementation of the library. I must use this Library and extend it in Kotlin.</p>
  
  <p>It seems odd to me that the java library is written such a way and expect it to be overridden but that is question for another day. </p>
  
  <pre class="lang-java prettyprint-override"><code>import java.util.Collections;
  import java.util.List;
  
  public abstract class ClassA {
      public List&lt;FooBuilder&lt;?&gt;&gt; getBuilder(Foo foo) {
          return Collections.emptyList();
      }
  }
  
  public class Foo {
  }
  
  public abstract class FooBuilder&lt;U extends FooBuilder.FooSettings&gt; {
      // implementation of Class
      abstract static class FooSettings {
          // implementation of Class
      }
  }
  </code></pre>
  
  <p><strong>Normally Java classes would override the method like such:</strong></p>
  
  <pre><code>import java.util.List;
  
  public class MyJavaClassA extends ClassA {
      @Override public List&lt;FooBuilder&lt;?&gt;&gt; getBuilder(final Foo foo) {
          // implementation
      }
  }
  </code></pre>
  
  <p><strong>But I am trying to write in Kotlin such that it looks like</strong>: Reminder that this Kotlin is depending on the Java library and does not have access to package public classes.</p>
  
  <pre><code>class MyKotlinClassA : ClassA() {
      override fun getBuilder(foo: Foo): MutableList&lt;FooBuilder&lt;*&gt;&gt; {
          // implementation
      }
  }
  </code></pre>
  
  <p>This causes error</p>
  
  <pre><code>'public' function exposes its 'public/*package*/' return type argument FooSettings
  </code></pre>