【发布时间】:2019-05-02 10:16:46
【问题描述】:
我将一个 Java 类转换为 kotlin,并收到提到的错误 Projections are not allowed for immediate arguments of a supertype
Java 类是
public class RecipeViewHolder extends ParentViewHolder {
private static final float INITIAL_POSITION = 0.0f;
private static final float ROTATED_POSITION = 180f;
@NonNull
private final ImageView mArrowExpandImageView;
private TextView mRecipeTextView;
private TextView position;
private TextView total;
public RecipeViewHolder(@NonNull View itemView) {
super(itemView);
mRecipeTextView = (TextView) itemView.findViewById(R.id.recipe_textview);
position = (TextView) itemView.findViewById(R.id.textViewPosition);
total = (TextView) itemView.findViewById(R.id.textViewTotal);
mArrowExpandImageView = (ImageView) itemView.findViewById(R.id.arrow_expand_imageview);
}
public void bind(@NonNull Recipe recipe) {
mRecipeTextView.setText(recipe.getName());
try {
position.setText("Position: " + recipe.getJson().getString("position"));
total.setText("Total Bid Amount: " + recipe.getJson().getString("type"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
转换后的 Kotlin 类是
//Error occurs here in Parentvireholder<*,*>
class RecipeViewHolder(itemView: View) : ParentViewHolder<*, *>(itemView) {
private val mArrowExpandImageView: ImageView
private val mRecipeTextView: TextView
private val position: TextView
private val total: TextView
init {
mRecipeTextView = itemView.findViewById<View>(R.id.recipe_textview) as TextView
position = itemView.findViewById<View>(R.id.textViewPosition) as TextView
total = itemView.findViewById<View>(R.id.textViewTotal) as TextView
mArrowExpandImageView = itemView.findViewById<View>(R.id.arrow_expand_imageview) as ImageView
}
fun bind(recipe: Recipe) {
mRecipeTextView.text = recipe.name
try {
position.text = "Position: " + recipe.json!!.getString("position")
total.text = "Total Bid Amount: " + recipe.json!!.getString("type")
} catch (e: JSONException) {
e.printStackTrace()
}
}
}
显示的评论出现错误。我已经尝试过 Any 修复,但显示 Type 参数不在其范围内
【问题讨论】:
-
请提供
ParentViewHolder的定义