title: Why parsing Gremlin query in Java isn't generic?
body: <p>I'm parsing a Gremlin query in Java (well, actually I'm writing Scala, and using the Groovy compiled JARs like it was Java).</p>
  
  <p><strong>The query is a String variable that is given by user input</strong>. In other words - I cannot tell what the query will be, I'm only assuming it's a valid Gremlin query (syntactically and logically).</p>
  
  <p>I started with a simple <code>Gremlin.compile(query)</code> that returns <code>Pipe</code> on which I'm iterating. However, according to <a href="https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java" rel="nofollow">the example</a>, one must invoke <code>.setStarts</code> prior to iterating the Pipe. And I must know what the is the runtime type <code>S</code> in my <code>Pipe&lt;S,E&gt;</code>.</p>
  
  <p>It feels like this API isn't generic enough, the following line from the example</p>
  
  <pre><code>pipe.setStarts(new SingleIterator&lt;Vertex&gt;(graph.getVertex(1)));
  </code></pre>
  
  <p>will work for some cases, but for Vertex Iteration for one example (<code>g.V()</code>) it will throw a CastException.</p>
  
  <p>Is there a way to work-around it?</p>
  
  <p>Perhaps using the underlying Script Engine (like the next examples in the link above) will help me to achieve more generic code?</p>