
reference.language.methods_abstract.html Maven / Gradle / Ivy
Methods
Abstract methods
Prompto supports abstract
methods, a special type of method, which must be overloaded.
Abstract methods are resolved at runtime based on the actual type of the value.
Abstract methods are well suited when no actual behaviour can be determined for an argument type (such as the below Shape).
In the below example, we do not know how to print a shape, only how to print specific shape types.
In order to print a list of shapes without knowing their type, we use an abstract method.
Abstract methods as arguments
Abstract methods can also be used as arguments for other methods:
In the above example, we show how to pass both a value: Hello and a method: displayScreen
to another method: someMethod
.
The method: someMethod
then invokes the method received as an argument, using the value also received as an argument.
The method caller is responsible for providing a non abstract method compatible with the argument's method type.
Please note that in the E dialect only, the Method:
keyword is required to let Prompto decide whether to pass displayScreen
directly as an argument, or to invoke it and pass the result. This is not required in O and M dialects, where method invocation requires parenthesis.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy