brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #817: Optimizations
Date Wed, 13 Sep 2017 11:27:44 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/817#discussion_r138592431
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/guava/TypeTokens.java ---
    @@ -24,6 +24,14 @@
     
     public class TypeTokens {
     
    +    // creating TypeToken is surprisingly expensive so cache these common ones
    +    public static TypeToken<String> STRING = TypeToken.of(String.class);
    --- End diff --
    
    If leaving as-is, then these should be `final`.
    
    I'd have gone for:
    ```
    public static final Map<Class<?>, TypeToken<?>> COMMON_TYPE_TOKENS =
ImmutableMap.<Class<?>, TypeToken<?>>builder()
            .put(String.class, TypeToken.of(String.class))
            ...
            .build();
    ```
    
    And:
    ```
    TypeToken<?> result = COMMON_TYPE_TOKENS.get(raw);
    if (result == null) result = TypeToken.of((Class<T>)raw);
    return (TypeToken<T>) result;
    ```


---

Mime
View raw message