1

我正在为 Android 开发一个基于注释处理器的库。我正在尝试提高库与 Kotlin 的兼容性。我有以下情况:

@BindType(value = "rss")
class RssFeed(
        @BindSqlColumn(columnType = ColumnType.UNIQUE)
        val uid: String,

        @BindXml(xmlType = XmlType.ATTRIBUTE)
        val version: String,

        @Bind("channel")
        @BindSqlRelation(foreignKey = "rssFeedId")
        val channels: List<Channel>,

        val id: Long
)

如您所见,这是 kotlin 中的一个简单数据类。我的图书馆将认为每个收藏都是“专业的”(具有通用性)。当我尝试在 Java 中反编译这个类时,我得到:

@BindType("rss")
@Metadata(
   mv = {1, 1, 10},
   bv = {1, 0, 2},
   k = 1,
   d1 = {"\u0000$\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\t\b\u0007\u0018\u00002\u00020\u0001B+\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003\u0012\f\u0010\u0005\u001a\b\u0012\u0004\u0012\u00020\u00070\u0006\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nR\u001c\u0010\u0005\u001a\b\u0012\u0004\u0012\u00020\u00070\u00068\u0006X\u0087\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0011\u0010\b\u001a\u00020\t¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000eR\u0016\u0010\u0002\u001a\u00020\u00038\u0006X\u0087\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u000f\u0010\u0010R\u0016\u0010\u0004\u001a\u00020\u00038\u0006X\u0087\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0011\u0010\u0010¨\u0006\u0012"},
   d2 = {"Lcom/abubusoft/rssreader/service/model/RssFeed;", "", "uid", "", "version", "channels", "", "Lcom/abubusoft/rssreader/service/model/Channel;", "id", "", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;J)V", "getChannels", "()Ljava/util/List;", "getId", "()J", "getUid", "()Ljava/lang/String;", "getVersion", "production sources for module app"}
)
public final class RssFeed {
   @BindSqlColumn(
      columnType = ColumnType.UNIQUE
   )
   @NotNull
   private final String uid;
   @BindXml(
      xmlType = XmlType.ATTRIBUTE
   )
   @NotNull
   private final String version;
   @Bind("channel")
   @BindSqlRelation(
      foreignKey = "rssFeedId"
   )
   @NotNull
   private final List channels;
   private final long id;

   @NotNull
   public final String getUid() {
      return this.uid;
   }

   @NotNull
   public final String getVersion() {
      return this.version;
   }

   @NotNull
   public final List getChannels() {
      return this.channels;
   }

   public final long getId() {
      return this.id;
   }

   public RssFeed(@NotNull String uid, @NotNull String version, @NotNull List channels, long id) {
      Intrinsics.checkParameterIsNotNull(uid, "uid");
      Intrinsics.checkParameterIsNotNull(version, "version");
      Intrinsics.checkParameterIsNotNull(channels, "channels");
      super();
      this.uid = uid;
      this.version = version;
      this.channels = channels;
      this.id = id;
   }
}

如您所见,有关通道字段的专业化信息丢失了:它被签名为 List。

预计 Java 版本的类保持 List 的特化。

这是我弄错了,或者只是 Kotlin 以这种方式工作?

更新

这是一种非常奇怪的行为。接口上使用的泛型被识别,类号上的泛型。

import android.arch.lifecycle.LiveData
import com.abubusoft.kripton.android.annotation.BindDao
import com.abubusoft.kripton.android.annotation.BindSqlDynamicWhere
import com.abubusoft.kripton.android.annotation.BindSqlSelect
import com.abubusoft.kripton.android.annotation.BindSqlUpdate
import com.abubusoft.kripton.example.rssreader.service.model.Article

@BindDao(Article::class)
interface DaoArticle {

    @BindSqlUpdate(where = "id=:id")
    fun update(id: Long, read: Boolean)

    @BindSqlSelect
    fun selectByChannel(@BindSqlDynamicWhere where: String): LiveData<List<Article>>

    @BindSqlSelect(where = "id=:id")
    fun selectById(id: Long): List<Article>

    @BindSqlSelect(where = "id in (:ids)")
    fun selectByChannelUd(ids: List<Long>): List<Article>

    @BindSqlSelect(where = "guid=:guid")
    fun selectByGuid(guid: String): Article
}
4

0 回答 0