4 ms·
I'm not sure how it is related to being first class. You cannot use a function as a variable.
by rat9988 3y ago
I'm not sure how it is related to being first class. You cannot use a function as a variable.
- AnimalMuppet 3y agoWell... you can define an interface, and have a class that implements the interface, and pass an instance of that class as a variable. That's not quite "passing a function as a variable", but it's kind of close if you squint.
- ivan_gammel 3y agoWrong answer since March 2014.
- vips7L 3y agoYou can. You just need to know what type of function it is first. Runnable r = () -> doSomething(); Supplier<String> a = () -> “hello world”;
- ivan_gammel 3y agoWhat do you mean? Since Java 8 you can assign a function to a variable, pass it as a parameter etc. Lambdas in Java are not pure, since they are converted to objects by compiler, but on user level they have all attributes of first class functions.
- deleted 3y ago[deleted]