我是Kotlin 的新手,正在try 用这种语言写一些项目.
'public' function exposes its 'public/*package*/' return type argument FooSettings
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 FooSettings
. However the problem is FooSettings
is package public only which means that I cannot access if in my Kotlin project.
我做了一些关于Kotlin泛型和使用in
或out
的研究,但是我无法解决这个问题.
在我的Kotlin项目中,我能做些什么来修复我看到的错误吗?
代码片段
This is sample of Java library class:个 注意,我没有办法更改库的实现.我必须使用这个图书馆,并将其扩展到Kotlin .
对我来说,java库是以这种方式编写的,并期望它被重写,这似乎很奇怪,但这是另一天的问题.
import java.util.Collections;
import java.util.List;
public abstract class ClassA {
public List<FooBuilder<?>> getBuilder(Foo foo) {
return Collections.emptyList();
}
}
public class Foo {
}
public abstract class FooBuilder<U extends FooBuilder.FooSettings> {
// implementation of Class
abstract static class FooSettings {
// implementation of Class
}
}
Normally Java classes would override the method like such:
import java.util.List;
public class MyJavaClassA extends ClassA {
@Override public List<FooBuilder<?>> getBuilder(final Foo foo) {
// implementation
}
}
But I am trying to write in Kotlin such that it looks like:提醒一下,这个Kotlin依赖于Java库,并且没有访问包公共类的权限.
class MyKotlinClassA : ClassA() {
override fun getBuilder(foo: Foo): MutableList<FooBuilder<*>> {
// implementation
}
}
This causes error
'public' function exposes its 'public/*package*/' return type argument FooSettings