在他的" 有效Java"一书中,Joshua Bloch写了关于equals()派生类在检查中添加其他字段的合同中发生的陷阱.通常情况下,这会破坏对称性,但Bloch声明"您可以在不违反equals合同的情况下将值组件添加到抽象类的子类".
显然这是真的,因为没有抽象类的实例,所以没有违反的对称性.但是其他子类呢?我写了这个例子,故意省略哈希码实现和空检查以保持代码简短:
public abstract class Vehicle {
private final String color;
public Vehicle(String color) {
this.color = color;
}
public String getColor() {
return color;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Vehicle)) return false;
Vehicle that = (Vehicle) o;
return color.equals(that.color);
}
}
public class Bicycle extends Vehicle {
public Bicycle(String color) {
super(color);
}
}
public class Car extends Vehicle …Run Code Online (Sandbox Code Playgroud) 我的Android应用程序与几乎所有其他应用程序一样,将其信息(用户的一些私有数据)存储在本地sqlite数据库中.现在我有一台平板电脑,我想知道是否有一种方便的方法可以跨多个设备同步数据并自动更新.大多数其他应用程序似乎使用自己的服务器,您必须为其创建一个帐户.
Android开发人员页面中称为" 同步到云 "的章节列出了两个解决方案:备份API和云消息传递.但似乎这些都没有提供我正在寻找的东西.虽然Backup API仅用于备份/恢复设备而不用于同步,但Cloud Messages Service需要一个正在运行的应用程序服务器.
我不希望我的用户创建帐户.此外,我不想将他们的私人数据存储在我的服务器上.到目前为止,我的应用程序甚至不需要"Internet连接"权限,如果可能的话,我希望它保持这种状态.
所以我的问题是:Google是否提供了云服务来保持应用数据同步?
我的 Maven 项目foo.web的源文件src/main在src/test. 当然,测试类使用“主”类。现在我想在运行时在另一个项目中使用测试类,所以我按照这些关于如何创建测试 jar 的说明进行操作。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这非常有效,web-SNAPSHOT-tests.jar创建了一个 jar ,我可以将它包含在我的其他项目中。
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>test-jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但似乎对 的依赖web-SNAPSHOT没有正确设置,因为在运行时我收到foo.web. 所以我添加了另一个依赖项:
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这没有任何改变。有谁知道这里有什么问题?