重写方法中的变量名称不正确 [英] Incorrect variable names in overridden methods

查看:164
本文介绍了重写方法中的变量名称不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我让Android Studio生成覆盖方法时,它会生成带有奇怪参数名称的方法。

When I let Android Studio generate override method it will generate the method with strange parameter names.

例如根据文档onCheckedChanged应该如下所示:

For instance according to documentation onCheckedChanged should look like this:

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){}

但是我得到了

public void onCheckedChanged(CompoundButton compoundButton, boolean b){}

或DatePickerDialog中的onDateSet:

or onDateSet in DatePickerDialog i got:

onDateSet(DatePicker datePicker, int i, int i1, int i2)

而不是

onDateSet(DatePicker view, int year, int month, int dayOfMonth)

我在项目中安装了Android SDK,安装了Android 27源代码。

I got Android SDK set up in a project and Sources for Android 27 installed.

任何想法?

谢谢

推荐答案

这是与 compil相关eSdkVersion ,它在 build.gradle 文件中定义。您应该为用作 compileSdkVersion 的API安装 Android SDK的源代码。因此,请尝试在SDK Manager中安装等于 compileSdkVersion 的源代码版本。

It is related to the compileSdkVersion which is defined in your build.gradle file. You should install Sources for Android SDK for the API you used as compileSdkVersion. So try to install sources version equal to compileSdkVersion in SDK Manager.

我设置了 compileSdkVersion 28 build.gradle 文件中。以下是安装源版本28之前和之后的结果(注意:之后您应该重新启动AndroidStudio):

I've set the compileSdkVersion 28 in build.gradle file. Here is the result before and after installing sources version 28 (Notice: You should restart AndroidStudio after that):

之前:

val textWatcher = object: TextWatcher {

    override fun afterTextChanged(p0: Editable?) {
    }

    override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
    }

    override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
    }
}

之后:

val textWatcher = object: TextWatcher {

    override fun afterTextChanged(s: Editable?) {
    }

    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
    }

    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
    }
}






U PDATE:10/23/2018



关于 AppCompat-v28 库的问题,例如 RecyclerView class,来自他们的 aar 工件。如果使用版本27.1.1库,则问题将消失。你正在使用的版本28的分布并不重要(例如28.0.0,28.0.0-alpha1,28.0.0-alpha3,28.0.0-rc1,28.0.0-rc2等)在版本28发行版中,抽象方法的参数名称被混淆。


UPDATE: 10/23/2018

The problem about AppCompat-v28 libraries such as RecyclerView class, comes from their aar artifacts. If you use version 27.1.1 libraries, the issue will gone. It doesn't matter what distribution of version 28 you are using (Such as 28.0.0, 28.0.0-alpha1, 28.0.0-alpha3, 28.0.0-rc1, 28.0.0-rc2, etc.) In all of version 28 distributions, the parameter names for abstract methods are obfuscated.

public abstract static class Adapter<VH extends RecyclerView.ViewHolder> {

    public Adapter() {
    }

    @NonNull
    public abstract VH onCreateViewHolder(@NonNull ViewGroup var1, int var2);

    public abstract void onBindViewHolder(@NonNull VH var1, int var2);

    ...
}

所以看来那里没有办法解决,直到它将在下一个发行版中修复。

So it seems that there is no way to solve, until it would be fixed in the next distributions.

这篇关于重写方法中的变量名称不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆