使用的类(在Java、第三方API中,不可更改):
public class BookmarkablePageLink<T> extends Link<T> {
public <C extends Page> BookmarkablePageLink(final String id, final Class<C> pageClass)
现在我想从Kotlin 那里给这个打电话:
item.queue(BookmarkablePageLink("link", bookmark.page))
bookmark.page
用Java表示,它是:public Class<? extends WebPage> getPage()
None of these work:
item.queue(BookmarkablePageLink("link", bookmark.page))
Error: Not enough information to infer parameter T in
constructor Bookmarkable PageLink<T : Any!, C : Page!>(...)
item.queue(BookmarkablePageLink<>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any, *>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any, WebPage>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any, in WebPage>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any, out WebPage>("link", bookmark.page))
item.queue(BookmarkablePageLink<Any, T : WebPage>("link", bookmark.page))
This would be the "hypothetically correct" way to do this in Javaish-speak (just the intention, but it's not real code), but this isn't supported by Kotlin:
item.queue(BookmarkablePageLink<Any, ? extends WebPage>("link", bookmark.page))
我最好的解决方法是这样,虽然很难看,但很管用:
item.queue(BookmarkablePageLink<Any, WebPage>("link", bookmark.page as Class<WebPage>))
Surprisingly in Java this was simply:
item.queue(new BookmarkablePageLink<>("link", bookmark.getPage() ));