You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "linenwei (Jira)" <ji...@apache.org> on 2020/09/29 17:04:00 UTC

[jira] [Updated] (KAFKA-10534) Modify the originals parameter type of the AbstractConfig class to avoid redundant judgments in the code

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

linenwei updated KAFKA-10534:
-----------------------------
          Flags: Patch
    Description: 
Source Code:
{code:java}
 @SuppressWarnings("unchecked")    
  public AbstractConfig(ConfigDef definition, Map<?, ?> originals,  Map<String, ?> configProviderProps, boolean doLog){ 
     /* check that all the keys are really strings */        
      for (Map.Entry<?, ?> entry : originals.entrySet())            
          if (!(entry.getKey() instanceof String))               
              throw new ConfigException(entry.getKey().toString(),       entry.getValue(), "Key must be a string.");


{code}
In source code, I find that originals map key {color:#FF0000}must be a string{color}. From my point of view,  why not use Map<String, ?> originals to replace Map<?, ?> originals? thus will not need to do a judgement for the key type. 


I'm not sure if I've thought about it, but if there are other reasons for doing this, I'd love to know why.

 

  was:
{code:java}
 @SuppressWarnings("unchecked")    
  public AbstractConfig(ConfigDef definition, Map<?, ?> originals,  Map<String, ?> configProviderProps, boolean doLog){ 
     /* check that all the keys are really strings */        
      for (Map.Entry<?, ?> entry : originals.entrySet())            
          if (!(entry.getKey() instanceof String))               
              throw new ConfigException(entry.getKey().toString(),       entry.getValue(), "Key must be a string.");


{code}


> Modify the originals parameter type of the AbstractConfig class to avoid redundant judgments in the code
> --------------------------------------------------------------------------------------------------------
>
>                 Key: KAFKA-10534
>                 URL: https://issues.apache.org/jira/browse/KAFKA-10534
>             Project: Kafka
>          Issue Type: Improvement
>          Components: clients
>    Affects Versions: 2.6.0
>            Reporter: linenwei
>            Priority: Trivial
>
> Source Code:
> {code:java}
>  @SuppressWarnings("unchecked")    
>   public AbstractConfig(ConfigDef definition, Map<?, ?> originals,  Map<String, ?> configProviderProps, boolean doLog){ 
>      /* check that all the keys are really strings */        
>       for (Map.Entry<?, ?> entry : originals.entrySet())            
>           if (!(entry.getKey() instanceof String))               
>               throw new ConfigException(entry.getKey().toString(),       entry.getValue(), "Key must be a string.");
> {code}
> In source code, I find that originals map key {color:#FF0000}must be a string{color}. From my point of view,  why not use Map<String, ?> originals to replace Map<?, ?> originals? thus will not need to do a judgement for the key type. 
> I'm not sure if I've thought about it, but if there are other reasons for doing this, I'd love to know why.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)