{"title":"Type testing and casting operators for interfaces in AL","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-interfaces-in-al-operators/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-interfaces-in-al-operators, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-interfaces-in-al-operators","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to use the `is` and `as` operators for type testing and casting interfaces in AL for Business Central.","date":"2025-06-27","meta":{"topic":"how-to"},"outline":[{"level":1,"title":"Type testing and casting operators for interfaces in AL","slug":"type-testing-and-casting-operators-for-interfaces-in-al","at":0,"chars":2745},{"level":2,"title":"Type testing with the is operator","slug":"type-testing-with-the-is-operator","at":797,"chars":568},{"level":2,"title":"Casting with the as operator","slug":"casting-with-the-as-operator","at":1365,"chars":588},{"level":2,"title":"Best practices","slug":"best-practices","at":1953,"chars":715},{"level":2,"title":"Related information","slug":"related-information","at":2668,"chars":77}],"text":"# Type testing and casting operators for interfaces in AL\n> APPLIES TO: Business Central 2024 release wave 2 and later.\nIn the AL language, you can define an interface, which is a syntactical contract that can be implemented by a nonabstract method. With Business Central 2024 release wave 2, you can also extend an interface, which allows for a more flexible and adaptable design. See devenv-interfaces-in-al-extend. In connection with the extensibility of interfaces, it's useful to be able to do type testing and casting of interfaces, because this allows you to work with interfaces in a more dynamic way, enabling you to check if an interface supports a specific method or property, and to cast it to a more specific type when needed. For this purpose, two operators is and as are available.\n## Type testing with the is operator\nType testing with the is operator is useful when extending interfaces because it allows you to test whether an instance of an interface or the content of a variant supports a specific interface.\nHere's the syntax for using the is keyword:\n```al\nprocedure TestInterface(intf: Interface IFoo)\nbegin\n    if intf is IBar then\n        Message('I also support IBar');\nend;\n```\nYou can also use the is operator with variants:\n```al\nprocedure TestVariant(v: Variant)\nbegin\n    if v is IBar then\n        Message('I support IBar');\nend;\n```\n## Casting with the as operator\nThe as operator is used for casting an instance of an interface to a specific interface. If the source interface doesn't implement the target interface, it throws an error at runtime. Here's an example:\n```al\nprocedure CastInterface(intf: Interface IFoo): Interface IBar\nbegin\n    exit(intf as IBar); // Throws an error if 'intf' doesn't implement 'IBar'\nend;\n```\nSimilarly, the as keyword works with variants:\n```al\nprocedure CastInterface(v: Variant): Interface IBar\nbegin\n    exit(v as IBar); // Throws an error if 'v' doesn't implement 'IBar'\nend;\n```\n## Best practices\nWhen working with interface operators in AL, follow these best practices:\n Use defensive programming - always check with is before casting with as to avoid runtime errors.\n Keep interfaces focused - design smaller, more specialized interfaces to make casting more predictable.\n Document interface relationships - when extending interfaces, clearly document the hierarchy to help other developers understand type relationships.\n Prefer explicit over implicit - when possible, design your code to use concrete types rather than relying heavily on runtime casting.\n Use consistent naming - follow a naming convention for interfaces to make code more readable, for example, prefixing the name with I.\n## Related information\ndevenv-interfaces-in-al\ndevenv-interfaces-in-al-extend"}