#2608 instanceof

Matthew Lohbihler Tue 30 May 2017

Total noob question. Is there an equivalent of instanceof in Fantom? I know about type(), but i want to know if the type of an instance can be resolved to any superclass, not just a specific class. Specifically, i want to know if x is a java.util.List, when it's concrete type could be an ArrayList, LinkedList, etc.

SlimerDude Tue 30 May 2017

Hey Matthew!

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

Matthew Lohbihler Tue 30 May 2017

Thanks!

Login or Signup to reply.