kotlin.reflect.KClass.isInstance(value: Any?) not workingHow to read the value of a private field from a different class in Java?Get property value from string using reflection in C#Best way of invoking getter by reflectionRuby craziness: Class vs Object?Using IsAssignableFrom with 'open' generic typesJava isInterface() does not return true for an InterfaceReflection not working on assembly that is loaded using Assembly.LoadFromJava - Class.isInstance() always returns falseParsing response from firestore not workingcannot start android on intellij

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

Are sweatpants frowned upon on flights?

Count the number of triangles

What will be the immediate action by the pilot and ATC if any plane blocks the runway while landing?

How could a self contained organic body propel itself in space

Is this position a forced win for Black after move 14?

How to prevent a hosting company from accessing a VM's encryption keys?

RAID0 instead of RAID1 or 5, is this crazy?

Why does Sauron not permit his followers to use his name?

Term used to describe a person who predicts future outcomes

Are spot colors limited and why CMYK mix is not treated same as spot color mix?

Why might one *not* want to use a capo?

If the UK Gov. has authority to cancel article 50 notification, why do they have to agree an extension with the EU

Is the Amazon rainforest the "world's lungs"?

Why does glibc's strlen need to be so complicated to run quickly?

Why nature prefers simultaneous events?

Does the Tribal card type have inherent mechanical implications?

To what extent should we fear giving offense?

Find most "academic" implementation of doubly linked list

Are there any to-scale diagrams of the TRAPPIST-1 system?

How do Barton (Hawkeye/Ronin) and Romanov (Black Widow) end up on the Benatar on Morag in 2014?

Drawing probabilities on a simplex in TikZ

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?

Stolen MacBook should I worry about my data?



kotlin.reflect.KClass.isInstance(value: Any?) not working


How to read the value of a private field from a different class in Java?Get property value from string using reflection in C#Best way of invoking getter by reflectionRuby craziness: Class vs Object?Using IsAssignableFrom with 'open' generic typesJava isInterface() does not return true for an InterfaceReflection not working on assembly that is loaded using Assembly.LoadFromJava - Class.isInstance() always returns falseParsing response from firestore not workingcannot start android on intellij






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying the follow



"simple string"::class.isInstance(kotlin.String)


But it return false!




I'm using



"org.jetbrains.kotlin:kotlin-reflect:1.3.21"




The another examples also fail



1::class.isInstance(kotlin.Int)
true::class.isInstance(Boolean)


Please, help me to understand it!










share|improve this question






























    0















    I'm trying the follow



    "simple string"::class.isInstance(kotlin.String)


    But it return false!




    I'm using



    "org.jetbrains.kotlin:kotlin-reflect:1.3.21"




    The another examples also fail



    1::class.isInstance(kotlin.Int)
    true::class.isInstance(Boolean)


    Please, help me to understand it!










    share|improve this question


























      0












      0








      0








      I'm trying the follow



      "simple string"::class.isInstance(kotlin.String)


      But it return false!




      I'm using



      "org.jetbrains.kotlin:kotlin-reflect:1.3.21"




      The another examples also fail



      1::class.isInstance(kotlin.Int)
      true::class.isInstance(Boolean)


      Please, help me to understand it!










      share|improve this question














      I'm trying the follow



      "simple string"::class.isInstance(kotlin.String)


      But it return false!




      I'm using



      "org.jetbrains.kotlin:kotlin-reflect:1.3.21"




      The another examples also fail



      1::class.isInstance(kotlin.Int)
      true::class.isInstance(Boolean)


      Please, help me to understand it!







      class kotlin reflection instanceof






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 21:23









      Abner EscócioAbner Escócio

      1,3771 gold badge8 silver badges22 bronze badges




      1,3771 gold badge8 silver badges22 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1















          You use the API incorrectly, the isInstance function does the opposite check as shown in the documentation:




          Returns true if [value] is an instance of this class on a given platform.




          The kotlin.Int line does not refer to a type, you miss the ::class.



          A possible solution is to flip the declaration:



          String::class.isInstance("a string") /// true
          Int::class.isInstance(42) /// true


          You may also compare KClass objects, e.g. 432::class == Int::class or use KClass functions isSubclassOf and isSuperclassOf






          share|improve this answer

























          • 432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

            – Abner Escócio
            Mar 28 at 4:38


















          2















          kotlin.String, kotlin.Int, and Boolean are used as values, so they refer to companion objects of the corresponding classes. So the first line checks whether the String companion object is a String and correctly tells you it isn't.






          share|improve this answer

























          • I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

            – Eugene Petrenko
            Mar 28 at 8:45






          • 1





            @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

            – Alexey Romanov
            Mar 28 at 17:08













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386660%2fkotlin-reflect-kclass-isinstancevalue-any-not-working%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          You use the API incorrectly, the isInstance function does the opposite check as shown in the documentation:




          Returns true if [value] is an instance of this class on a given platform.




          The kotlin.Int line does not refer to a type, you miss the ::class.



          A possible solution is to flip the declaration:



          String::class.isInstance("a string") /// true
          Int::class.isInstance(42) /// true


          You may also compare KClass objects, e.g. 432::class == Int::class or use KClass functions isSubclassOf and isSuperclassOf






          share|improve this answer

























          • 432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

            – Abner Escócio
            Mar 28 at 4:38















          1















          You use the API incorrectly, the isInstance function does the opposite check as shown in the documentation:




          Returns true if [value] is an instance of this class on a given platform.




          The kotlin.Int line does not refer to a type, you miss the ::class.



          A possible solution is to flip the declaration:



          String::class.isInstance("a string") /// true
          Int::class.isInstance(42) /// true


          You may also compare KClass objects, e.g. 432::class == Int::class or use KClass functions isSubclassOf and isSuperclassOf






          share|improve this answer

























          • 432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

            – Abner Escócio
            Mar 28 at 4:38













          1














          1










          1









          You use the API incorrectly, the isInstance function does the opposite check as shown in the documentation:




          Returns true if [value] is an instance of this class on a given platform.




          The kotlin.Int line does not refer to a type, you miss the ::class.



          A possible solution is to flip the declaration:



          String::class.isInstance("a string") /// true
          Int::class.isInstance(42) /// true


          You may also compare KClass objects, e.g. 432::class == Int::class or use KClass functions isSubclassOf and isSuperclassOf






          share|improve this answer













          You use the API incorrectly, the isInstance function does the opposite check as shown in the documentation:




          Returns true if [value] is an instance of this class on a given platform.




          The kotlin.Int line does not refer to a type, you miss the ::class.



          A possible solution is to flip the declaration:



          String::class.isInstance("a string") /// true
          Int::class.isInstance(42) /// true


          You may also compare KClass objects, e.g. 432::class == Int::class or use KClass functions isSubclassOf and isSuperclassOf







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 22:55









          Eugene PetrenkoEugene Petrenko

          3,28318 silver badges27 bronze badges




          3,28318 silver badges27 bronze badges















          • 432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

            – Abner Escócio
            Mar 28 at 4:38

















          • 432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

            – Abner Escócio
            Mar 28 at 4:38
















          432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

          – Abner Escócio
          Mar 28 at 4:38





          432::class == Int::class it work but Int::class.isInstance(42) not. Thanks!

          – Abner Escócio
          Mar 28 at 4:38













          2















          kotlin.String, kotlin.Int, and Boolean are used as values, so they refer to companion objects of the corresponding classes. So the first line checks whether the String companion object is a String and correctly tells you it isn't.






          share|improve this answer

























          • I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

            – Eugene Petrenko
            Mar 28 at 8:45






          • 1





            @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

            – Alexey Romanov
            Mar 28 at 17:08















          2















          kotlin.String, kotlin.Int, and Boolean are used as values, so they refer to companion objects of the corresponding classes. So the first line checks whether the String companion object is a String and correctly tells you it isn't.






          share|improve this answer

























          • I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

            – Eugene Petrenko
            Mar 28 at 8:45






          • 1





            @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

            – Alexey Romanov
            Mar 28 at 17:08













          2














          2










          2









          kotlin.String, kotlin.Int, and Boolean are used as values, so they refer to companion objects of the corresponding classes. So the first line checks whether the String companion object is a String and correctly tells you it isn't.






          share|improve this answer













          kotlin.String, kotlin.Int, and Boolean are used as values, so they refer to companion objects of the corresponding classes. So the first line checks whether the String companion object is a String and correctly tells you it isn't.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 4:28









          Alexey RomanovAlexey Romanov

          118k27 gold badges224 silver badges368 bronze badges




          118k27 gold badges224 silver badges368 bronze badges















          • I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

            – Eugene Petrenko
            Mar 28 at 8:45






          • 1





            @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

            – Alexey Romanov
            Mar 28 at 17:08

















          • I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

            – Eugene Petrenko
            Mar 28 at 8:45






          • 1





            @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

            – Alexey Romanov
            Mar 28 at 17:08
















          I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

          – Eugene Petrenko
          Mar 28 at 8:45





          I was looking for a Java's Class#isAssignableFrom(obj) function analog. It is interesting to spot that kotlin.Int means companion object, but kotlin.Int::class means the KClass of not (and not a KClass of the companion)

          – Eugene Petrenko
          Mar 28 at 8:45




          1




          1





          @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

          – Alexey Romanov
          Mar 28 at 17:08





          @EugenePetrenko Do you mean Class#isAssignableFrom(Class<?>)? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetric isSubclassOf).

          – Alexey Romanov
          Mar 28 at 17:08

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386660%2fkotlin-reflect-kclass-isinstancevalue-any-not-working%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현