[Oberon] Life without local procedures
Richard Hable
informujo at aon.at
Sat Feb 24 21:09:42 CET 2018
On 2018-02-24 14:02, Claudio Nieder wrote:
> Maybe nicer using functions:
>
> package test;
>
> import java.util.function.Function;
>
> public class Global
> {
> public static void main(final String[] a)
> {
> final int i=5;
> final Function<Integer,Integer> q=x -> {
> return x*i;
> };
> System.out.println(q.apply(7));
> }
> }
I didn't like this solution, because the function signature (names and
types of the function and its parameters) is declared in an unusual way
and the function is not separated clearly from the main method's statements.
Although longer, I think the following code is easier to read:
public static void main(final String[] a){
final int i=5;
class LocalMethods {
int q(int x){
return x*i;
}
}
LocalMethods localMethods = new LocalMethods();
System.out.println(localMethods.q(7));
}
Richard
More information about the Oberon
mailing list