代码之家  ›  专栏  ›  技术社区  ›  xcesco

Java中的KOTLIN转换失去了集合的专业化?

  •  1
  • xcesco  · 技术社区  · 7 年前

    我正在为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;
       }
    }
    

    正如您可以注意到的,有关通道字段专门化的信息将丢失:它作为列表签名。

    预计Java版本的类具有列表的专用性。

    这是我犯的错误,或者只是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
    }
    
    0 回复  |  直到 7 年前
    推荐文章