[ 
https://issues.apache.org/jira/browse/TINKERPOP-3015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17798300#comment-17798300
 ] 

Christopher Smith commented on TINKERPOP-3015:
----------------------------------------------

There exists a compilation error with that exact code in 3.5, and I suspect it 
also exists in 3.6 and 3.7. Specifically, even if your code words by 
coincidence, I believe inspecting the generated bytecode (e.g., with {{javap 
-v}}) will show that the wrong overload is being selected.

{code}Collection<String> asString = List.of("a", "b");

@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<Object> asObject = (Collection) asString;

gts.V().hasId(P.within(asString)).iterate();
gts.V().hasId(P.within(asObject)).iterate();
{code}

correctly produces the following bytecode snippet, where you can see that the 
invocation of {{hasId(P<String>)}} is resolved to {{hasId(Object, Object...)}}

{code}
   #60 = InterfaceMethodref #61.#63       // 
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.hasId:(Ljava/lang/Object;[Ljava/lang/Object;)Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #61 = Class              #62           // 
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal
   #62 = Utf8               
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal
   #63 = NameAndType        #64:#65       // 
hasId:(Ljava/lang/Object;[Ljava/lang/Object;)Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #64 = Utf8               hasId
   #65 = Utf8               
(Ljava/lang/Object;[Ljava/lang/Object;)Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #66 = InterfaceMethodref #61.#67       // 
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.iterate:()Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #67 = NameAndType        #68:#69       // 
iterate:()Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #68 = Utf8               iterate
   #69 = Utf8               
()Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
   #70 = InterfaceMethodref #61.#71       // 
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.hasId:(Lorg/apache/tinkerpop/gremlin/process/traversal/P;)Lorg/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal;
{code}

The fact that this produces the desired results in the current implementation 
is an implementation detail and not guaranteed by the API semantics.

> Use wildcard instead of Object for hasId predicates
> ---------------------------------------------------
>
>                 Key: TINKERPOP-3015
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3015
>             Project: TinkerPop
>          Issue Type: Improvement
>    Affects Versions: 3.5.7, 3.6.5
>            Reporter: Christopher Smith
>            Priority: Minor
>
> From both {{GraphTraversal}} and {{__}}, the {{hasId(P)}} steps specify a 
> {{P<Object>}}. Common predicates, such as {{within}}, propagate the generic 
> type from their own arguments, so that this produces a compile-time error:
> {code}
> Collection<String> ids = ...
> g.V().hasId(P.within(ids))
> {code}
> I believe that without loss of safety, the signature in both locations could 
> be changed to {{P<?>}}, making the typical case of "here's a collection of 
> IDs of known type" work smoothly.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to