Regarding Java subclasses inheriting methods that return “this”
问题 Have a class Car with a public method public Car myself() { return this; } Have a subclass Ferrari , and a variable foo that contains a Ferrari object. Finally, Ferrari bar = foo.myself(); This will warn you, because the method myself() returns a Car object, rather than the expected Ferrari . Note: I know that the example is stupid because you'd just do bar = foo . It's just an example. Solutions: Override the myself() method in Ferrari . Cast the Car object to a Ferrari object when assigning