You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by "lilu (Jira)" <ji...@apache.org> on 2022/08/30 13:12:00 UTC

[jira] [Updated] (CURATOR-651) Why use Collection instead of List as return value

     [ https://issues.apache.org/jira/browse/CURATOR-651?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

lilu updated CURATOR-651:
-------------------------
    Description: 
org.apache.curator.x.discovery.ServiceDiscovery#queryForInstances

The implementation class internally calls org.apache.curator.x.discovery.details.ServiceDiscoveryImpl#queryForInstances(java.lang.String, org.apache.zookeeper.Watcher)

The specific code is:

 
{code:java}
@Override
public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception
{
    return queryForInstances(name, null);
}

List<ServiceInstance<T>> queryForInstances(String name, Watcher watcher) throws Exception
{
// ...
}{code}
Why is List implicitly converted to Collection?

This way I won't be able to use List.get(0) directly. but requires a conversion.

May I ask what is the reason for doing this?

Thank you very much.

  was:
org.apache.curator.x.discovery.ServiceDiscovery#queryForInstances

The implementation class internally calls org.apache.curator.x.discovery.details.ServiceDiscoveryImpl#queryForInstances(java.lang.String, org.apache.zookeeper.Watcher)

The specific code is:

 
{code:java}
@Override
public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception
{
    return queryForInstances(name, null);
}

List<ServiceInstance<T>> queryForInstances(String name, Watcher watcher) throws Exception
{
// ...
}{code}
Why is List implicitly converted to Collection?

This way I won't be able to use List.get(0) directly. but requires a conversion.

May I ask what is the reason for doing this?

 

       Priority: Major  (was: Trivial)

> Why use Collection instead of List as return value
> --------------------------------------------------
>
>                 Key: CURATOR-651
>                 URL: https://issues.apache.org/jira/browse/CURATOR-651
>             Project: Apache Curator
>          Issue Type: Bug
>            Reporter: lilu
>            Assignee: Jordan Zimmerman
>            Priority: Major
>
> org.apache.curator.x.discovery.ServiceDiscovery#queryForInstances
> The implementation class internally calls org.apache.curator.x.discovery.details.ServiceDiscoveryImpl#queryForInstances(java.lang.String, org.apache.zookeeper.Watcher)
> The specific code is:
>  
> {code:java}
> @Override
> public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception
> {
>     return queryForInstances(name, null);
> }
> List<ServiceInstance<T>> queryForInstances(String name, Watcher watcher) throws Exception
> {
> // ...
> }{code}
> Why is List implicitly converted to Collection?
> This way I won't be able to use List.get(0) directly. but requires a conversion.
> May I ask what is the reason for doing this?
> Thank you very much.



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