SARL, like Java, is a statically typed language. In fact, it completely supports Java’s type system, including the primitive types like int or boolean, arrays and all the Java classes, interfaces, enumerations and annotations that reside on the class path.
Java generic types are fully supported as well: you can define type parameters on methods and classes and pass type arguments to generic types just as you are used to from Java. The type system and its conformance and casting rules are implemented as defined in the Java Language Specification.
One of the problems with Java is that you are forced to write type signatures over and over again. That is why so many people do not like static typing. But this is in fact not a problem of static typing, but simply a problem with Java. Although SARL is statically typed just like Java, you rarely have to write types down because they can be computed from the context.
In addition to Java’s auto-boxing to convert primitives to their corresponding wrapper
types (e.g. int is automatically converted to Integer when needed), there are
additional conversion rules in SARL: arrays are automatically converted to
List<ComponentType>
and vice versa.
Resembling and supporting every aspect of Java’s type system ensures that there is no impedance mismatch between Java and SARL. This means that SARL and Java are 100% interoperable. There are no exceptional cases and you do not have to think in two worlds. You can invoke SARL code from Java and vice versa without any surprises or hassles.
This documentation is based on documentations from the Xtext and Xtend projects, and from the Java tutorials. Thank you to the contributors to these documents.
Copyright © 2014-2025 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.15.1.