asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Documentation: type() missing #229

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It looks like in https://code.google.com/p/objectify-appengine/wiki/Queries 
under Executing Queries there is a small bug:

I believe this:

// You can filter keys as well
List<Car> range = ofy().load().filterKey(">=", startKey).filterKey("<", 
endKey).list(); // type() cast missing

Should be this:

// You can filter keys as well
List<Car> range = ofy().load().type(Car.class).filterKey(">=", 
startKey).filterKey("<", endKey).list();

Even though startKey/endKey is Key<Car>, type Object seems to be passed to 
.list() so that List<Object> is finally returned, not List<Car>, as specified 
in the documentation.

Or do you do a magic trick here which I overlooked?

Original issue reported on code.google.com by oliver.h...@gmail.com on 5 Feb 2015 at 1:45

GoogleCodeExporter commented 9 years ago
I'm not quite sure if there is a clean way around this generics issue, but the 
"correct" way to solve it with the current API is a cast:

List<Car> range = (List<Car>)ofy().load().filterKey(">=", 
startKey).filterKey("<", endKey).list();

Specifying type() has a specific meaning - it issues a query for that specific 
type, whereas typeless load() could return any type (and thus returns 
List<Object>).

I have updated the docs. Thanks for catching that.

Original comment by lhori...@gmail.com on 5 Feb 2015 at 6:23

GoogleCodeExporter commented 9 years ago
Casting would require a raw (List) cast. Instead I just changed the docs to 
return List<Object>. The examples are not supposed to be a tutorial on java's 
lousy implementation of generics :-/

Original comment by lhori...@gmail.com on 5 Feb 2015 at 6:28