#2631 How to check types?

isomorph Mon 21 Aug 2017

In Java you can easily check your types with "instanceof" - is there an equivalent or other way to proof your types?

matthew Mon 21 Aug 2017

You can get the type of an object using obj.typeof. Then you can use type.fits to see if it is instance of another type

go4 Mon 21 Aug 2017

The is operator: typeChecking.

And it's better to ask questions on StackOverflow.

SlimerDude Tue 22 Aug 2017

And it's better to ask questions on StackOverflow.

Good call!

A response from a recent instanceof forum post sums up what has been said already:


Try is and isnot - see Type Checking:

69 is Num             // --> true
69 isnot Num          // --> false
(69 as Num) is Float  // --> false

There is also Type.fits() - see fits:

69.typeof.fits(Num#)  // --> true
69.typeof.fits(List#) // --> false

Login or Signup to reply.