Understanding Common Methods

I want to call the following method:

<C extends Iterable<R>> C as(Class<C> container)

(Anyone familiar with spring -data-neo4j will recognize this as a method of the EndResult class).

I'm not quite happy with generics yet, and I don't understand what to call this method.

ArrayList<Point> pointlist = neo4jtemplate.findAll(Line.class).as( ?? );

The method findAll()returns the iterability of the Neo4j base nodes and binds .as(). the method to it converts this result into an iterability of another type. If I wanted to convert it to iterable of objects (for example) Point, what would I call this method?

+3
source share
1 answer

The parameter containermust be an object of the class class that implements the interface Iterablefor the type R. For instance:

neo4jtemplate.findAll(Line.class).as(MyClassThatIteratesOverTypeR.class);

If the type is Iterable Point, it is possible:

class PointIterator implements Iterable<Point> {
    // you would have to implement all the method of Iterator
}

:

class PointIterator extends ArrayList<Point> { } // That all you need

neo4jtemplate.findAll(Line.class).as(PointIterator.class);

, :

neo4jtemplate.findAll(Line.class).as(ArrayList<R>.class); // can't do this
+4

All Articles