@AutoValue - "无法找到符号类生成"错误 [英] @AutoValue - "cannot find symbol class Generated" Error

查看:1210
本文介绍了@AutoValue - "无法找到符号类生成"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到无法找到符号类生成的,而使用@AutoValue注释。

I am getting "cannot find symbol class Generated" while using the @AutoValue annotation.

public abstract  class Office{

public static Office create(String cityName, String companyName, String regionName) {
    return new AutoValue_Office(cityName, companyName, regionName);
}


public abstract String getCompanyName();
public abstract String getCityName();
public abstract String getRegionName();
}

依赖摇篮
    编译com.google.auto.value:自动值:1.0-RC1

Gradle dependency compile 'com.google.auto.value:auto-value:1.0-rc1'

另外,如何添加唯一入选的属性来平等和散列code函数。

Also, how can add only selected properties to equals and hashcode function.

推荐答案

的问题是,您使用的是Android版本不具有注释javax.annotations.Generated(这是在Java 6中添加)。如答案描述<一个你可以手动添加href=\"http://stackoverflow.com/questions/9403917/how-do-i-add-javax-annotation-generated-to-java-se-5\">this问题。

The problem is that you are using a version of Android that doesn't have the annotation javax.annotations.Generated (which was added in Java 6). You could add that manually as described in the answer to this question.

关于从平等和散列code排除某些性能问题,目前要做到这一点没有完美的方法。通常情况下做到这一点的愿望表明需要应包括财产分割成一个单独的类和使用,在平等和哈希code。或者,您可以添加非最终字段办公室类设置。例如,如果没有被列入regionName,你可以这样写:

Concerning the question of excluding certain properties from equals and hashCode, there is currently no perfect way to do that. Often the desire to do this indicates a need to separate the properties that should be included into a separate class and use that in equals and hashCode. Alternatively, you could add non-final fields to the Office class and set them. For example, if regionName was not to be included, you could write something like this:

@AutoValue
public abstract class Office {
  private String regionName;

  public abstract String getCompanyName();
  public abstract String getCityName();
  public String getRegionName() {
    return regionName;
  }

  public static Office create(String cityName, String companyName, String regionName) {
    Office office = new AutoValue_Office(cityName, companyName);
    office.regionName = regionName;
    return office;
  }
}

主要缺点是regionName不是终点,这样你就不会得到同样的保障来自其他线程访问它,你的其他属性做。

The main disadvantage is that regionName is not final, so you don't get the same guarantees about access to it from other threads as you do for the other properties.

这篇关于@AutoValue - &QUOT;无法找到符号类生成&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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