2021年3月21日星期日

What does just calling .getClass(); do? [duplicate]

I'm looking at some decompiled code and seeing .getClass();, i.e. nothing being done with its return value.

  public String forLocale(Locale locale, String keyword) {      Stream var10000 = getLocaleMappingList(locale, this.getSupportedLocales());      Map var10001 = this.translations;      var10001.getClass();      Map<String, String> translation = (Map)var10000.map(var10001::get).filter((m) -> {        return m.containsKey(keyword);      }).findFirst().orElse(this.translations.get(FALLBACK));      Preconditions.checkState(translation.containsKey(keyword), keyword + " is not a valid translation key");      return (String)translation.get(keyword);    }  

What is that for? Was it in the original code like that? (So far I haven't seen an instance of decompiled code not matching up at least line-wise to source code.)

It kind of looks like an assertion, but then what is achieved by doing that as opposed to letting things go wrong at var10001::get? Or is it more about performance?


Update

Here's the bytecode. Cool thing to learn how to do!

 // access flags 0x1    public forLocale(Ljava/util/Locale;Ljava/lang/String;)Ljava/lang/String;     L0      LINENUMBER 184 L0      ALOAD 1      ALOAD 0      INVOKEVIRTUAL com/spotify/i18n/Translations.getSupportedLocales ()Ljava/util/Set;      INVOKESTATIC com/spotify/i18n/Translations.getLocaleMappingList (Ljava/util/Locale;Ljava/util/Collection;)Ljava/util/stream/Stream;      ALOAD 0      GETFIELD com/spotify/i18n/Translations.translations : Ljava/util/Map;      DUP      INVOKEVIRTUAL java/lang/Object.getClass ()Ljava/lang/Class;      POP      INVOKEDYNAMIC apply(Ljava/util/Map;)Ljava/util/function/Function; [        // handle kind 0x6 : INVOKESTATIC        java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;        // arguments:        (Ljava/lang/Object;)Ljava/lang/Object;,         // handle kind 0x9 : INVOKEINTERFACE        java/util/Map.get(Ljava/lang/Object;)Ljava/lang/Object; itf,         (Ljava/util/Locale;)Ljava/util/Map;      ]  
https://stackoverflow.com/questions/66686859/what-does-just-calling-getclass-do March 18, 2021 at 03:53PM

没有评论:

发表评论