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;
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
add a comment |
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
add a comment |
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
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
class kotlin reflection instanceof
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
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
432::class == Int::class
it work butInt::class.isInstance(42)
not. Thanks!
– Abner Escócio
Mar 28 at 4:38
add a comment |
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.
I was looking for a Java'sClass#isAssignableFrom(obj)
function analog. It is interesting to spot thatkotlin.Int
means companion object, butkotlin.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 meanClass#isAssignableFrom(Class<?>)
? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetricisSubclassOf
).
– Alexey Romanov
Mar 28 at 17:08
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
432::class == Int::class
it work butInt::class.isInstance(42)
not. Thanks!
– Abner Escócio
Mar 28 at 4:38
add a comment |
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
432::class == Int::class
it work butInt::class.isInstance(42)
not. Thanks!
– Abner Escócio
Mar 28 at 4:38
add a comment |
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
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
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 butInt::class.isInstance(42)
not. Thanks!
– Abner Escócio
Mar 28 at 4:38
add a comment |
432::class == Int::class
it work butInt::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
add a comment |
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.
I was looking for a Java'sClass#isAssignableFrom(obj)
function analog. It is interesting to spot thatkotlin.Int
means companion object, butkotlin.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 meanClass#isAssignableFrom(Class<?>)
? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetricisSubclassOf
).
– Alexey Romanov
Mar 28 at 17:08
add a comment |
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.
I was looking for a Java'sClass#isAssignableFrom(obj)
function analog. It is interesting to spot thatkotlin.Int
means companion object, butkotlin.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 meanClass#isAssignableFrom(Class<?>)
? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetricisSubclassOf
).
– Alexey Romanov
Mar 28 at 17:08
add a comment |
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.
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.
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'sClass#isAssignableFrom(obj)
function analog. It is interesting to spot thatkotlin.Int
means companion object, butkotlin.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 meanClass#isAssignableFrom(Class<?>)
? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetricisSubclassOf
).
– Alexey Romanov
Mar 28 at 17:08
add a comment |
I was looking for a Java'sClass#isAssignableFrom(obj)
function analog. It is interesting to spot thatkotlin.Int
means companion object, butkotlin.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 meanClass#isAssignableFrom(Class<?>)
? That would be kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/… (and nicely, there's a symmetricisSubclassOf
).
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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