motorcb
motorcb

Reputation: 1051

Android LiveData<List<User>> cast to LiveData<List<?extednds IEntity>>

I have generic problem,

I have LiveData<List<User>>, object User implement IEntity.

How to cast LiveData<List<User>> to LiveData<List<IEntity>>?

  package cz.roomlivedata.entity;
  import  android.arch.persistence.room.Entity;
  import android.arch.persistence.room.Index; 
  import android.arch.persistence.room.PrimaryKey;

  @Entity(indices = {@Index(value = "id", unique = true)}) 
  public class User implements IEntity {

  @PrimaryKey(autoGenerate = true) public int id;

  private String name;

  private String name; public User(String name) { this.name = name; } 

  public String getName() { return name; } 

  public void setName(String name) { this.name = name; } 
}

code

Upvotes: 1

Views: 1300

Answers (1)

niketshah09
niketshah09

Reputation: 490

This is how I removed while using kotlin.

abstract class X

class Y: X()

fun getValues(): MutableLiveData<out List<X>> {
    return MutableLiveData<List<Y>>()
}

out keyword helped me. So basically what in and out keyword does have to be done in java manually.

Upvotes: 1

Related Questions